From 9038ee2efaec9debd73e1b2edb492aece7806c6c Mon Sep 17 00:00:00 2001 From: eezd Date: Thu, 5 Nov 2026 13:43:06 +0800 Subject: [PATCH] Parse SEC official release datelines with September abbreviations --- backend/src/alphapulse/core/us_news.py | 3 +++ backend/tests/test_us_official_news.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/backend/src/alphapulse/core/us_news.py b/backend/src/alphapulse/core/us_news.py index 8a38d25..5258e49 100644 --- a/backend/src/alphapulse/core/us_news.py +++ b/backend/src/alphapulse/core/us_news.py @@ -69,6 +69,7 @@ def published(value: str) -> tuple[datetime, str]: if not isinstance(value, str): raise ValueError('官方材料缺少可识别的发布时间') value = value.strip().replace('\xa0', ' ') + value = re.sub(r'\bSept(?=\.? \d)', 'Sep', value) if re.fullmatch(r'\d{4}-\d{2}-\d{2}', value): return datetime.fromisoformat(value).replace(tzinfo=UTC), 'date' try: @@ -120,6 +121,8 @@ def article(source: str, html: str, url: str, *, release_date: str | None = None if not title: raise ValueError('官方正文缺少标题') values = sel.css('meta[property="article:published_time"]::attr(content), meta[name="DC.date.issued"]::attr(content), meta[name="dcterms.date"]::attr(content), time::attr(datetime)').getall() + if source == 'sec': + values += sel.css('.field--name-dynamic-twig-fieldnode-press-release-lead-in').xpath('normalize-space(.)').getall() for script in sel.css('script[type="application/ld+json"]::text').getall(): try: data = json.loads(script) diff --git a/backend/tests/test_us_official_news.py b/backend/tests/test_us_official_news.py index 06b1af3..b967415 100644 --- a/backend/tests/test_us_official_news.py +++ b/backend/tests/test_us_official_news.py @@ -1376,3 +1376,13 @@ def test_doj_captioned_photo_is_not_a_document_gap(trading): item, = asyncio.run(collect()) assert item['extra']['attachments'] == [] assert not obj.cursor.get('attachment_retries') + + +def test_sec_uses_official_dateline_not_last_reviewed_date(): + body = '''

SEC regulatory announcement

+
Washington D.C., Sept. 30, 2026 —
+
The Commission proposes digital asset market rules for regulated financial institutions.
+
Last Reviewed or Updated: November 5, 2026
''' + item = article('sec', body, 'https://www.sec.gov/newsroom/press-releases/example') + assert item['published_at'] == datetime(2026, 9, 30, tzinfo=UTC) + assert item['extra']['published_at_precision'] == 'date'