FIX: first_seen re-stamp bug — persist true source publish date, idempotent upsert, backfill DB

This commit is contained in:
Epictetus
2026-07-13 22:16:59 +00:00
parent 7e33ffd36f
commit 424da91364
8 changed files with 167 additions and 138 deletions
+4 -19
View File
@@ -33,6 +33,7 @@ from datetime import datetime, timedelta, timezone
from html import unescape
from adapters import SourceAdapter
from adapters._store import true_first_seen, upsert_entries
# arXiv API
ARXIV_API = "http://export.arxiv.org/api/query"
@@ -443,6 +444,7 @@ class ArxivAdapter(SourceAdapter):
raw_meta["applied_domain"] = paper["_applied_domain"]
now_str = now.strftime("%Y-%m-%dT%H:%M:%SZ")
first_seen = true_first_seen(raw_meta, "arxiv", now_str)
entries.append({
"source": "arxiv",
"source_id": source_id,
@@ -453,7 +455,7 @@ class ArxivAdapter(SourceAdapter):
"category_tags": json.dumps(tags),
"signal_score": score,
"raw_metadata": json.dumps(raw_meta),
"first_seen": now_str,
"first_seen": first_seen,
"last_updated": now_str,
})
@@ -491,24 +493,7 @@ if __name__ == "__main__":
conn.commit()
cur = conn.cursor()
stored = 0
for entry in entries:
try:
cur.execute("""
INSERT OR REPLACE INTO entries
(source, source_id, url, title, extracted_text, summary,
category_tags, signal_score, raw_metadata, first_seen, last_updated)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
entry["source"], entry["source_id"], entry["url"], entry["title"],
entry["extracted_text"], entry["summary"],
entry["category_tags"], entry["signal_score"],
entry["raw_metadata"], entry["first_seen"], entry["last_updated"],
))
stored += 1
except Exception as e:
print(f" DB error: {e}")
stored = upsert_entries(conn, entries)
conn.commit()
conn.close()
print(f" Stored {stored} entries")