refactor(notifications): unify email sending via _send_email; standardize crawler notifications\n\n- Extract _send_email and have send_email/send_custom_email share it\n- BaseCrawler: centralize _send_notifications and add _build_email hook\n- BarronsCrawler: override _build_email to keep original subject/body\n- OpenInsiderCrawler: remove custom _send_notifications, add _build_email\n- /notify_test: use crawler _build_email + send_custom_email for emails

This commit is contained in:
2025-09-04 22:59:51 +08:00
parent e89567643b
commit b2c58c0560
5 changed files with 51 additions and 51 deletions

View File

@@ -75,7 +75,13 @@ def create_app(crawler) -> Flask:
if channel == 'email':
if not c.config.email:
return {"error": "Email config not set"}
notif.send_email(test_pick, c.config.email)
# Build subject/body using crawler's formatting hook for consistency
if hasattr(c, '_build_email'):
subject, body = c._build_email(test_pick)
else:
subject = f"{getattr(c, 'name', '通知測試')}(測試)"
body = notif.format_email_body(test_pick)
notif.send_custom_email(subject, body, c.config.email)
elif channel == 'webhook':
if not c.config.webhook_url:
return {"error": "Webhook URL not set"}