fix: Script bug fixes (bare except, timezone, regex, test)

- collector.py, compliance_checker.py, trends.py: bare except -> specific
- db_helper.py: datetime.now() -> timezone.utc (8 occurrences)
- compliance_checker.py: regex \x08 -> \b word boundary + import json
- search_providers.py: minor fixes
- test_new_features.py: service reachability check retry

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Yuzhiran Dev
2026-06-16 08:24:50 +08:00
parent d601a26850
commit 63a6fabc00
6 changed files with 33 additions and 30 deletions
+10 -11
View File
@@ -6,7 +6,7 @@
import sys
import os
from pathlib import Path
from datetime import datetime, date, timedelta
from datetime import datetime, date, timedelta, timezone
from typing import Optional, Dict, List
# 加载 .env(在 scripts/ 目录下运行时需要)
@@ -84,17 +84,17 @@ def update_topic_status(topic_id: str, status: str, compliance_score: Optional[i
if not topic:
return False
topic.status = status
topic.updated_at = datetime.now()
topic.updated_at = datetime.now(timezone.utc)
if compliance_score is not None:
topic.compliance_score = compliance_score
if reviewed_at is not None:
topic.reviewed_at = reviewed_at
if status == 'review' and topic.generated_at is None:
topic.generated_at = datetime.now()
topic.reviewed_at = topic.reviewed_at or datetime.now()
topic.generated_at = datetime.now(timezone.utc)
topic.reviewed_at = topic.reviewed_at or datetime.now(timezone.utc)
if status == 'ready':
topic.ready_at = datetime.now().date()
topic.reviewed_at = topic.reviewed_at or datetime.now()
topic.reviewed_at = topic.reviewed_at or datetime.now(timezone.utc)
if status == 'published':
topic.published_at = datetime.now().date()
db.commit()
@@ -198,14 +198,14 @@ def save_topics_to_db(topics_data: List[Dict]):
if t.get('ready_at'):
try:
existing.ready_at = datetime.strptime(t['ready_at'], '%Y-%m-%d').date()
except:
except Exception:
pass
if t.get('published_at'):
try:
existing.published_at = datetime.strptime(t['published_at'], '%Y-%m-%d').date()
except:
except Exception:
pass
existing.updated_at = datetime.now()
existing.updated_at = datetime.now(timezone.utc)
else:
new_topic = Topic(
id=t['id'],
@@ -225,8 +225,8 @@ def save_topics_to_db(topics_data: List[Dict]):
published_at=datetime.strptime(t['published_at'], '%Y-%m-%d').date() if t.get('published_at') else None,
compliance_score=t.get('compliance_score', 100),
platform_urls=t.get('platform_urls', {}),
created_at=datetime.now(),
updated_at=datetime.now()
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc)
)
db.add(new_topic)
db.commit()
@@ -246,7 +246,6 @@ def save_article(topic_id: str, platform: str, html_content: str, *, title: str
from app.models import Article
article_id = f"{platform}_{topic_id}"
existing = db.query(Article).filter(Article.id == article_id).first()
now = datetime.now()
if existing:
existing.html_content = html_content
if title: