#!/usr/bin/env python3 """SM-022 candidate (conda-forge): docs say packages "take around 15 minutes to be available for installation after their publication" (conda-forge.org/docs/maintainer/understanding_conda_forge/life_cycle/). Every 3 minutes: fetch the CDN's rss.xml (the 100 most recent updates, regenerated by each CDN sync), record headers (Last-Modified, Cloudflare age) and lastBuildDate, and for every package version seen for the first time look up its files' upload_time on anaconda.org. Lag (per version) = first time the version is in the CDN feed minus its latest file upload before that feed's build. Stdlib only. Files: ~/cfpoll/feeds.jsonl, ~/cfpoll/versions.jsonl, ~/cfpoll/state.json. Started 2026-10-17.""" import datetime as dt, email.utils, json, os, re, urllib.request, xml.etree.ElementTree as ET D = os.path.expanduser("~/cfpoll"); os.makedirs(D, exist_ok=True); ST = os.path.join(D, "state.json") UA = {"User-Agent": "markovianprotocol.com second-measurement (hello@markovianprotocol.com)"} now = dt.datetime.now(dt.timezone.utc) r = urllib.request.urlopen(urllib.request.Request("https://conda.anaconda.org/conda-forge/rss.xml", headers=UA), timeout=60) body = r.read(); hdr = {k.lower(): v for k, v in r.headers.items()} ch = ET.fromstring(body).find("channel"); lbd = email.utils.parsedate_to_datetime(ch.findtext("lastBuildDate")) feed = {"polled_at": now.isoformat(), "last_build": lbd.isoformat(), "last_modified": hdr.get("last-modified"), "cf_age": hdr.get("age"), "cf_status": hdr.get("cf-cache-status")} open(os.path.join(D, "feeds.jsonl"), "a").write(json.dumps(feed) + "\n") st = json.load(open(ST)) if os.path.exists(ST) else {"seen": {}} new = 0 for it in ch.findall("item"): m = re.match(r"(\S+) (\S+) \[(.*)\]", it.findtext("title") or "") if not m: continue name, ver, subdirs = m.group(1), m.group(2), [s.strip() for s in m.group(3).split(",")] key = f"{name}=={ver}" if key in st["seen"]: continue st["seen"][key] = now.isoformat(); new += 1 row = {"pkg": name, "version": ver, "subdirs": subdirs, "rss_pubdate": email.utils.parsedate_to_datetime(it.findtext("pubDate")).isoformat(), "first_seen_poll": now.isoformat(), "first_seen_build": lbd.isoformat(), "cf_age": hdr.get("age")} try: files = json.load(urllib.request.urlopen(urllib.request.Request(f"https://api.anaconda.org/package/conda-forge/{name}/files", headers=UA), timeout=60)) ups = sorted(f["upload_time"] for f in files if f.get("version") == ver and "main" in (f.get("labels") or [])) before = [u for u in ups if dt.datetime.fromisoformat(u.replace(" ", "T")) <= lbd] row.update({"files": len(ups), "first_upload": ups[0] if ups else None, "last_upload_before_build": before[-1] if before else None}) except Exception as e: row["api_error"] = repr(e)[:120] open(os.path.join(D, "versions.jsonl"), "a").write(json.dumps(row) + "\n") if len(st["seen"]) > 50000: st["seen"] = dict(sorted(st["seen"].items(), key=lambda kv: kv[1])[-20000:]) json.dump(st, open(ST, "w")) print(now.isoformat(timespec="seconds"), "build", lbd.isoformat(timespec="seconds"), "age", hdr.get("age"), "new", new)