feat(archive): sync dossiers 48-70, 2026-11-28 wire harvest, zoology dossiers 65-69, and lecture transcripts

This commit is contained in:
Hermes Agent committed 2026-11-29 21:19:14 +00:00
1 parent 85c5bab5e7
commit 3b5bb057ef
79 files changed
+18063 -1415

No files matched your search

+140 -2
View File
@@ -147,11 +147,14 @@ def resolve_target_dates(
now_utc: datetime.datetime,
explicit_date: str | None = None,
mode: str = "auto",
archive_dir: str | None = None,
) -> dict[str, Any]:
"""
Resolve target UTC date paying strict attention to the 00:00 GMT boundary paradox.
- At 00:00 GMT (00:00-05:59 UTC) or mode='closing-bell', target_date is (now_utc - 24h)
because Wikipedia Portal:Current_events for the brand-new UTC day is empty at 00:00:00 GMT.
- If archive_dir contains prior dated dossiers with a 1-day gap before yesterday_str,
auto-selects the earliest missing recent UTC date when explicit_date is omitted.
- In mode='live' or when now_utc.hour >= 6, target_date is now_utc.strftime('%Y-%m-%d'),
while also retaining yesterday_utc for Wikipedia completeness.
"""
@@ -169,6 +172,18 @@ def resolve_target_dates(
target_dt = yesterday_dt
target_str = yesterday_str
reason = "00:00_GMT_closing_bell_paradox_rule (now_utc - 24h)"
if archive_dir and os.path.isdir(archive_dir):
existing_dates = {
m.group(1)
for fn in os.listdir(archive_dir)
if (m := re.search(r"dossier-news-(\d{4}-\d{2}-\d{2})\.md$", fn))
}
two_days_ago_dt = now_utc - datetime.timedelta(days=2)
two_days_ago_str = two_days_ago_dt.strftime("%Y-%m-%d")
if two_days_ago_str not in existing_dates:
target_dt = two_days_ago_dt
target_str = two_days_ago_str
reason = "00:00_GMT_closing_bell_backfill (now_utc - 48h missing from archive)"
else:
target_dt = now_utc
target_str = today_str
@@ -420,6 +435,104 @@ def extract_candidate_entities(headlines: list[dict[str, str]]) -> list[dict[str
return candidates[:320]
_ONES = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen",
]
_TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
_UNIT_WORDS = {
"tn": "trillion", "trillion": "trillion",
"bn": "billion", "b": "billion", "billion": "billion",
"m": "million", "mn": "million", "million": "million",
"k": "thousand", "thousand": "thousand",
"%": "percent",
}
def _int_to_words(n: int) -> str:
if n < 0:
return "minus " + _int_to_words(-n)
if n < 20:
return _ONES[n]
if n < 100:
t, r = divmod(n, 10)
return _TENS[t] + ("" if r == 0 else " " + _ONES[r])
if n < 1000:
h, r = divmod(n, 100)
return _ONES[h] + " hundred" + ("" if r == 0 else " " + _int_to_words(r))
for scale_val, scale_name in ((1_000_000_000_000, "trillion"), (1_000_000_000, "billion"), (1_000_000, "million"), (1000, "thousand")):
if n >= scale_val:
q, r = divmod(n, scale_val)
return _int_to_words(q) + " " + scale_name + ("" if r == 0 else " " + _int_to_words(r))
return str(n)
def token_to_spoken_english(raw_tok: str) -> str:
"""Convert a quantitative token like '$11B', '12,000', '$1.5tn', or '481' into spoken English words."""
s = raw_tok.strip()
m = re.match(r"^([$€£])?(\d[\d,]*)(?:\.(\d+))?([a-zA-Z%]+)?$", s)
if not m:
return s.lower()
_curr, int_part, dec_part, unit_part = m.groups()
int_val = int(int_part.replace(",", ""))
words = [_int_to_words(int_val)]
if dec_part:
words.append("point")
for ch in dec_part:
words.append(_ONES[int(ch)])
if unit_part:
u_low = unit_part.lower()
if u_low in _UNIT_WORDS:
words.append(_UNIT_WORDS[u_low])
else:
words.append(u_low)
return " ".join(words)
def extract_quantitative_anchors(headlines: list[dict[str, str]]) -> list[dict[str, Any]]:
"""
Non-destructively extract quantitative/numeric tokens and their entity context into a
parallel sidecar stream (`quantitative_anchors`), leaving `entities` 100% lexical.
"""
quant_items: list[dict[str, Any]] = []
seen_pairs = set()
quant_re = re.compile(r"(?<![a-zA-Z0-9])([$€£]?\d[\d,]*(?:\.\d+)?(?:tn|bn|mn|b|m|k|%)?)\b", re.I)
for idx, item in enumerate(headlines):
hl = item["headline"]
src = item["source"]
story_tag = f"H{idx+1:02d}:{src}"
# Find primary capitalized entity in the headline for context pairing
ent_matches = [
m.group(1).strip("'-")
for m in re.finditer(r"\b([A-Z][a-zA-Z0-9'-]{1,}(?:\s+[A-Z][a-zA-Z0-9'-]{2,})?)\b", hl)
if m.group(1).lower() not in {"the", "and", "for", "with", "after", "from", "into", "over", "why", "how"}
]
primary_entity = ent_matches[0] if ent_matches else f"H{idx+1:02d}"
for qm in quant_re.finditer(hl):
q_tok = qm.group(1)
# Skip bare calendar year 2026 unless attached to currency/unit
if q_tok in {"2025", "2026", "2027"}:
continue
key = (primary_entity.lower(), q_tok.lower())
if key in seen_pairs:
continue
seen_pairs.add(key)
spoken_eng = token_to_spoken_english(q_tok)
quant_items.append(
{
"story": story_tag,
"entity_context": primary_entity,
"q_digit": q_tok,
"q_spoken_eng": spoken_eng,
"headline": hl,
}
)
return quant_items[:80]
def main() -> int:
parser = argparse.ArgumentParser(description="Pre-collect current events & Ingglish AQ matrix.")
parser.add_argument("--date", default=None, help="Explicit YYYY-MM-DD target date override.")
@@ -437,7 +550,7 @@ def main() -> int:
if not os.path.exists(args.archive_dir) and os.path.exists("/workspace/ingglish-aq-archive"):
args.archive_dir = "/workspace/ingglish-aq-archive"
now_utc = datetime.datetime.now(datetime.timezone.utc)
date_info = resolve_target_dates(now_utc, explicit_date=args.date, mode=args.mode)
date_info = resolve_target_dates(now_utc, explicit_date=args.date, mode=args.mode, archive_dir=args.archive_dir)
# Fetch all 3 portals concurrently
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
@@ -450,9 +563,12 @@ def main() -> int:
all_headlines = wiki_items + bbc_items + ap_items
candidates = extract_candidate_entities(all_headlines)
quant_candidates = extract_quantitative_anchors(all_headlines)
strings_to_translate = list(
{h["headline"] for h in all_headlines} | {c["eng"] for c in candidates}
{h["headline"] for h in all_headlines}
| {c["eng"] for c in candidates}
| {qc["q_spoken_eng"] for qc in quant_candidates}
)
translations = batch_translate_ingglish(strings_to_translate, workdir=args.workdir)
@@ -544,6 +660,26 @@ def main() -> int:
continuity_info = load_prior_dossiers(args.archive_dir)
enriched_quant_anchors = []
for qc in quant_candidates:
sp_eng = qc["q_spoken_eng"]
sp_ing = translations.get(sp_eng, sp_eng.lower())
d_aq = compute_aq(qc["q_digit"])
s_aq = compute_aq(sp_ing)
enriched_quant_anchors.append(
{
"story": qc["story"],
"entity_context": qc["entity_context"],
"q_digit": qc["q_digit"],
"q_digit_aq": d_aq,
"q_spoken_eng": sp_eng,
"q_spoken_ing": sp_ing,
"q_spoken_aq": s_aq,
"spoken_prime_rank": PRIME_INDEX.get(s_aq),
"headline": qc["headline"],
}
)
payload = {
"temporal_metadata": date_info,
"continuity": continuity_info,
@@ -553,6 +689,7 @@ def main() -> int:
"ap_headlines": len(ap_items),
"total_headlines": len(enriched_headlines),
"candidate_entities": len(enriched_entities),
"quantitative_anchors": len(enriched_quant_anchors),
"twin_prime_headlines": len(twin_prime_headlines),
"cross_story_collision_classes": len(cross_story_collisions),
"isometric_locks": len(isometric_locks),
@@ -561,6 +698,7 @@ def main() -> int:
"shared_prime_attractors": shared_prime_attractors,
"cross_story_collisions": cross_story_collisions,
"isometric_locks": isometric_locks,
"quantitative_anchors": enriched_quant_anchors,
"headlines": enriched_headlines,
"entities": enriched_entities,
}