#!/usr/bin/env -S uv run --script """Load the follow-up spreadsheet into the store. bin/import-sheet SHEET.xlsx # into config.yaml's database bin/import-sheet SHEET.xlsx --db x.db # or a named one bin/import-sheet SHEET.xlsx --dry-run # say what would happen The sheet is the one kept by hand: a title in A1, the header on row 3, one applicant per row after that. Each prose column becomes an event in that applicant's story, with the speaker the column implies. The state and the tags are guessed from the words in those columns; the guess is a starting point to correct on the page, not a verdict. An applicant already in the store gets the events only, never a second row or a changed state. Dates: the sheet's prose names days without years, so every imported event is undated and its source says which sheet it came from. """ from __future__ import annotations import argparse import pathlib import sys import openpyxl import yaml THIS_DIR = pathlib.Path(__file__).resolve().parent.parent sys.path.insert(0, str(THIS_DIR)) from store import DEFAULT_STATE, Store # noqa: E402 # The header row's labels, as the sheet spells them, to the names used here. COLUMNS = { "No. in List": "list_no", "Committer Name": "name", "ASF address": "asf_address", "GitHub Account Name": "github_login", "GitHub address": "github_email", "ASF Project Activity": "roles", "Status per Anthropic": "program_said", "ASF Action (Sally / Responsible AI team)": "we_told", "User Comments / Issue": "applicant_wrote", "Additional Comments": "applicant_wrote_more", } # Which words in the three prose columns point at which state. First match # wins, so the more specific lines come first. STATE_RULES = [ ("suspended", ("suspended",)), ("approved", ("not yet activated", "activation link did not work")), ("active", ("activated",)), ("approved", ("approved",)), ("held", ("not reapply", "please hold", "still holding")), ("form_blocked", ("couldn't find any public repositories", "won't submit", "unable to pick", "can't", "cannot")), ("no_record", ("no application found", "no record")), ("not_applied", ("what are my chances",)), ] TAG_RULES = [ ("no_github_history", ("public repositories", "contribution history", "unable to pick", "doesn't notice me")), ("wrong_repo", ("repository other than",)), ("activation_missing", ("activation email", "haven't received", "not yet activated", "spam")), ("activation_broken", ("activation link did not work",)), ("corporate_account", ("corporate", "company", "team subscription")), ("account_trouble", ("suspended", "delete account", "can't be used")), ("non_code_role", ("security team", "pre-date github", "not actively contributing", "no actively coding")), ("priority", ("priority", "asap")), ] COUNTRY_RULES = [("US", ("united states", "us resident", "lives in the us")), ("CH", ("switzerland",))] def read_rows(path: pathlib.Path) -> list[dict]: ws = openpyxl.load_workbook(path, read_only=True).worksheets[0] rows = ws.iter_rows(values_only=True) header = None out = [] for raw in rows: cells = [str(c).strip() if c is not None else "" for c in raw] if header is None: if "ASF address" in cells: header = [COLUMNS.get(c, c) for c in cells] continue if not any(cells): continue out.append(dict(zip(header, cells, strict=False))) if header is None: sys.exit("no header row: expected a row holding 'ASF address'") return out def guess(rules, text: str) -> list[str]: found = [] for key, words in rules: if any(w in text for w in words): found.append(key) return found def list_number(value: str) -> int | None: """The master-list number, when the cell holds one ('99.0'); None for NEW or a note.""" try: return int(float(value)) except ValueError: return None def main() -> None: ap = argparse.ArgumentParser(description=__doc__.split("\n", 1)[0]) ap.add_argument("sheet", type=pathlib.Path) ap.add_argument("--db", type=pathlib.Path, help="SQLite file; default from config.yaml") ap.add_argument("--dry-run", action="store_true") args = ap.parse_args() db = args.db if db is None: cfg = yaml.safe_load((THIS_DIR / "config.yaml").read_text()) db = THIS_DIR / cfg["database"] store = Store(":memory:" if args.dry_run else db) source = f"sheet {args.sheet.name}" added = updated = skipped = 0 for row in read_rows(args.sheet): address = row["asf_address"] if "@" not in address: print(f"skip: no ASF address for {row['name']!r}") skipped += 1 continue asf_id = address.split("@", 1)[0].lower() prose = " ".join((row["program_said"], row["we_told"], row["applicant_wrote"], row["applicant_wrote_more"])) lower = prose.lower() if store.exists(asf_id): updated += 1 else: state = (guess(STATE_RULES, lower) or [DEFAULT_STATE])[0] _ = store.add( asf_id, state=state, name=row["name"], github_login=row["github_login"], github_email=row["github_email"], roles=row["roles"], country=(guess(COUNTRY_RULES, lower) or [""])[0], list_no=list_number(row["list_no"]), ) for tag in guess(TAG_RULES, (lower + " " + row["roles"].lower())): store.add_tag(asf_id, tag) added += 1 print(f"{asf_id:20s} {state:13s} {' '.join(store.get(asf_id).tags)}") if row["list_no"] and list_number(row["list_no"]) is None: _ = store.add_event(asf_id, "note", f"Sheet marks this one: {row['list_no']}", source=source) for kind in ("program_said", "we_told", "applicant_wrote"): if row[kind] and row[kind] != "N/A": _ = store.add_event(asf_id, kind, row[kind], source=source) if row["applicant_wrote_more"]: _ = store.add_event(asf_id, "applicant_wrote", row["applicant_wrote_more"], source=source) print(f"\n{added} added, {updated} already here (events appended), {skipped} skipped") if args.dry_run: print("dry run: nothing written") if __name__ == "__main__": main()