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:
@@ -8,11 +8,13 @@ import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from app.crawlers.base import BaseCrawler
|
||||
from app.services import notifications as notif
|
||||
|
||||
|
||||
class BarronsCrawler(BaseCrawler):
|
||||
def __init__(self, config, logger):
|
||||
super().__init__(name="Barron's 股票推薦", config=config, logger=logger, data_filename='barrons_data.json')
|
||||
# Name used in generic notifications; include emoji to match previous subject
|
||||
super().__init__(name="📈 Barron's 新股票推薦", config=config, logger=logger, data_filename='barrons_data.json')
|
||||
self.url = "https://www.barrons.com/market-data/stocks/stock-picks?mod=BOL_TOPNAV"
|
||||
self.headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
@@ -68,3 +70,8 @@ class BarronsCrawler(BaseCrawler):
|
||||
self.stats['errors'] += 1
|
||||
return []
|
||||
|
||||
# Keep Barron's specific email formatting (subject + body)
|
||||
def _build_email(self, items: List[Dict]):
|
||||
subject = f"📈 Barron's 新股票推薦 ({len(items)}條)"
|
||||
body = notif.format_email_body(items)
|
||||
return subject, body
|
||||
|
Reference in New Issue
Block a user