Collection as an ETL pipeline; runs_clean.csv from every source; Report a run
- collection/pipeline.yaml declares every source (extract kind, transform, privacy rules, load target, run source); `python -m collection update|build` - extract keeps data/raw/<source>/current + previous only (git-ignored); data/manifest.json records the current raw checksum and change date - transforms are pure; validate checks runs against data/dictionary.yaml before load; load writes byte-stable files only when they change - data/public/runs_clean.csv: every run from every source with a new `source` column (reddit spreadsheet, reddit thread, reported, bot, reddit pdf); the sheet's own row label moves to `entry`; run_id is text - bot importer ported to Python (same output as bot.js on the fixture); labels and crosswalk in collection/specs/bot.yaml, written into graph.js - Reddit through the official API (result links to add by hand); the 12 result pages move to collection/manual/reddit_results.yaml - "Report a run": a GitHub issue form generated from collection/specs/report_form.yaml, collected as source "reported", plus a site tab pointing to it, the community spreadsheet and the megathread - analysis and the route model read runs_clean.csv (sources in measures.yaml); stats.json and policy.json unchanged apart from the factor's new name - daily workflow runs the pipeline; the raw store is kept between runs in the Actions cache, encrypted with RAW_ARCHIVE_KEY Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
61bc50583c
commit
3b24a11f5a
@@ -0,0 +1,45 @@
|
||||
"""Reddit megathreads (raw: the threads' comment trees from the official API) -> dragonkind.com result links that
|
||||
are not yet in collection/manual/reddit_results.yaml. Usernames and comment text are never kept: only the result
|
||||
ids and the comment permalinks, for the report, so a person can read the result page and add it by hand."""
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from ..common import read_yaml
|
||||
|
||||
RESULT_RE = re.compile(r"dragonkind\.com/results/(THRESH-[A-Z0-9]+)", re.I)
|
||||
|
||||
|
||||
def _comments(node):
|
||||
"""Every comment in a listing tree."""
|
||||
if isinstance(node, list):
|
||||
for x in node:
|
||||
yield from _comments(x)
|
||||
elif isinstance(node, dict):
|
||||
data = node.get("data") or {}
|
||||
if node.get("kind") in ("t1", "t3"):
|
||||
yield data
|
||||
for key in ("children", "replies"):
|
||||
if isinstance(data.get(key), (dict, list)):
|
||||
yield from _comments(data[key])
|
||||
|
||||
|
||||
def transform(raw_path, spec, ctx):
|
||||
threads = json.loads(Path(raw_path).read_text(encoding="utf-8"))
|
||||
known = {r["id"].upper() for r in read_yaml(spec["transform"]["manual"])["results"]}
|
||||
found = {}
|
||||
for tid, tree in sorted(threads.items()):
|
||||
for c in _comments(tree):
|
||||
for m in RESULT_RE.finditer((c.get("body") or "") + " " + (c.get("selftext") or "") + " " + (c.get("url") or "")):
|
||||
rid = m.group(1).upper()
|
||||
if rid not in known and rid not in found:
|
||||
found[rid] = "https://www.reddit.com" + (c.get("permalink") or f"/comments/{tid}/")
|
||||
return {"new_results": [{"id": k, "comment": v} for k, v in sorted(found.items())]}
|
||||
|
||||
|
||||
def describe(old, new):
|
||||
rs = new["new_results"]
|
||||
if not rs:
|
||||
return ["no new result links in the threads"]
|
||||
return [f"{len(rs)} result link(s) not yet in collection/manual/reddit_results.yaml (read each page, then add it):"] + \
|
||||
[f" - https://dragonkind.com/results/{r['id']} (posted at {r['comment']})" for r in rs[:40]]
|
||||
Reference in New Issue
Block a user