claude code review
This commit is contained in:
@@ -11,7 +11,7 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# Config
|
||||
SCRIPT_DIR = Path.home() / ".openclaw/workspace/scripts/news_digest"
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
DB_PATH = SCRIPT_DIR / "news_digest.db"
|
||||
CONFIG_PATH = SCRIPT_DIR / "config.json"
|
||||
|
||||
@@ -24,11 +24,14 @@ def run_news_digest():
|
||||
# Fetch new articles using run.sh (handles uv dependencies)
|
||||
fetch_cmd = [
|
||||
str(SCRIPT_DIR / "run.sh"),
|
||||
"-v"
|
||||
]
|
||||
|
||||
|
||||
# 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:
|
||||
print(f"Fetch failed: {result.stderr}", file=sys.stderr)
|
||||
return None
|
||||
@@ -40,31 +43,22 @@ def run_news_digest():
|
||||
"-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:
|
||||
print(f"Query failed: {result.stderr}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
# Parse JSON - find the JSON array in stdout
|
||||
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]
|
||||
|
||||
|
||||
# Parse JSON output
|
||||
try:
|
||||
articles = json.loads(json_output)
|
||||
articles = json.loads(result.stdout)
|
||||
return articles
|
||||
except json.JSONDecodeError as e:
|
||||
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 []
|
||||
|
||||
def format_email(articles):
|
||||
@@ -90,8 +84,9 @@ def format_email(articles):
|
||||
|
||||
# Sort categories
|
||||
category_order = ['Tech', 'China', 'World', 'Other']
|
||||
|
||||
for cat in category_order:
|
||||
ordered_cats = category_order + [c for c in by_category if c not in category_order]
|
||||
|
||||
for cat in ordered_cats:
|
||||
if cat not in by_category:
|
||||
continue
|
||||
|
||||
@@ -134,12 +129,15 @@ Content-Type: text/plain; charset=utf-8
|
||||
{body}"""
|
||||
|
||||
cmd = [
|
||||
str(Path.home() / ".local/bin/himalaya"),
|
||||
"himalaya",
|
||||
"message", "send",
|
||||
"-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
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user