claude code review
This commit is contained in:
@@ -11,7 +11,7 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
SCRIPT_DIR = Path.home() / ".openclaw/workspace/scripts/news_digest"
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||||
DB_PATH = SCRIPT_DIR / "news_digest.db"
|
DB_PATH = SCRIPT_DIR / "news_digest.db"
|
||||||
CONFIG_PATH = SCRIPT_DIR / "config.json"
|
CONFIG_PATH = SCRIPT_DIR / "config.json"
|
||||||
|
|
||||||
@@ -24,11 +24,14 @@ def run_news_digest():
|
|||||||
# Fetch new articles using run.sh (handles uv dependencies)
|
# Fetch new articles using run.sh (handles uv dependencies)
|
||||||
fetch_cmd = [
|
fetch_cmd = [
|
||||||
str(SCRIPT_DIR / "run.sh"),
|
str(SCRIPT_DIR / "run.sh"),
|
||||||
"-v"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Run fetch (this saves articles to DB and generates summaries)
|
# Run fetch (this saves articles to DB and generates summaries)
|
||||||
result = subprocess.run(fetch_cmd, capture_output=True, text=True, cwd=SCRIPT_DIR)
|
try:
|
||||||
|
result = subprocess.run(fetch_cmd, capture_output=True, text=True, cwd=SCRIPT_DIR, timeout=300)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
print("Fetch timed out after 300s", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print(f"Fetch failed: {result.stderr}", file=sys.stderr)
|
print(f"Fetch failed: {result.stderr}", file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
@@ -40,31 +43,22 @@ def run_news_digest():
|
|||||||
"-f", "id,title,url,summary,feed_name,category"
|
"-f", "id,title,url,summary,feed_name,category"
|
||||||
]
|
]
|
||||||
|
|
||||||
result = subprocess.run(query_cmd, capture_output=True, text=True, cwd=SCRIPT_DIR)
|
try:
|
||||||
|
result = subprocess.run(query_cmd, capture_output=True, text=True, cwd=SCRIPT_DIR, timeout=30)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
print("Query timed out after 30s", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print(f"Query failed: {result.stderr}", file=sys.stderr)
|
print(f"Query failed: {result.stderr}", file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Parse JSON - find the JSON array in stdout
|
# Parse JSON output
|
||||||
stdout = result.stdout.strip()
|
|
||||||
|
|
||||||
# Find where JSON array starts and ends
|
|
||||||
start_idx = stdout.find('[')
|
|
||||||
end_idx = stdout.rfind(']')
|
|
||||||
|
|
||||||
if start_idx == -1 or end_idx == -1 or start_idx >= end_idx:
|
|
||||||
print("No valid JSON array found", file=sys.stderr)
|
|
||||||
print(f"Debug output: {stdout[:500]}", file=sys.stderr)
|
|
||||||
return []
|
|
||||||
|
|
||||||
json_output = stdout[start_idx:end_idx+1]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
articles = json.loads(json_output)
|
articles = json.loads(result.stdout)
|
||||||
return articles
|
return articles
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
print(f"Failed to parse JSON: {e}", file=sys.stderr)
|
print(f"Failed to parse JSON: {e}", file=sys.stderr)
|
||||||
print(f"Raw output: {json_output[:500]}", file=sys.stderr)
|
print(f"Raw output: {result.stdout[:500]}", file=sys.stderr)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def format_email(articles):
|
def format_email(articles):
|
||||||
@@ -90,8 +84,9 @@ def format_email(articles):
|
|||||||
|
|
||||||
# Sort categories
|
# Sort categories
|
||||||
category_order = ['Tech', 'China', 'World', 'Other']
|
category_order = ['Tech', 'China', 'World', 'Other']
|
||||||
|
ordered_cats = category_order + [c for c in by_category if c not in category_order]
|
||||||
for cat in category_order:
|
|
||||||
|
for cat in ordered_cats:
|
||||||
if cat not in by_category:
|
if cat not in by_category:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -134,12 +129,15 @@ Content-Type: text/plain; charset=utf-8
|
|||||||
{body}"""
|
{body}"""
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
str(Path.home() / ".local/bin/himalaya"),
|
"himalaya",
|
||||||
"message", "send",
|
"message", "send",
|
||||||
"-a", "Youlu" # Account name from config.toml
|
"-a", "Youlu" # Account name from config.toml
|
||||||
]
|
]
|
||||||
|
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, input=message)
|
try:
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, input=message, timeout=30)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
return False, "himalaya timed out after 30s"
|
||||||
return result.returncode == 0, result.stderr
|
return result.returncode == 0, result.stderr
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user