Download _scripts/make_authors.py from imecai/cl-agentic-vault: direct link, hf CLI and curl.
- Browser
- Download file 3.91 kB
-
https://huggingface.co/datasets/imecai/cl-agentic-vault/resolve/main/_scripts/make_authors.py
- Command line
-
hf download hf://datasets/imecai/cl-agentic-vault/_scripts/make_authors.py
-
curl -L -o make_authors.py https://huggingface.co/datasets/imecai/cl-agentic-vault/resolve/main/_scripts/make_authors.py
3.91 kB
| #!/usr/bin/env python3 | |
| """Create author notes from paper-note frontmatter and keep their paper | |
| lists fresh. | |
| One note per unique author name in papers/influences frontmatter. Each note | |
| carries a GENERATED paper-links section between markers — real wikilinks, so | |
| they register in Obsidian's graph and render outside Obsidian (export, | |
| GitHub/HF views), unlike dataview blocks. The generated section is refreshed | |
| on every run; anything the user writes outside the markers is preserved. | |
| python3 _scripts/make_authors.py | |
| Also reports author notes that no paper references anymore (possible | |
| spelling drift) — it never deletes them. | |
| """ | |
| import glob | |
| import os | |
| import re | |
| import unicodedata | |
| VAULT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| AUTHORS_DIR = os.path.join(VAULT, "authors") | |
| STUB = """--- | |
| tags: [author] | |
| --- | |
| # {name} | |
| <!-- Enrich freely above/below; the section between markers is regenerated. --> | |
| {papers_section}""" | |
| MARK_A = "<!-- GENERATED:papers -->" | |
| MARK_B = "<!-- /GENERATED:papers -->" | |
| def papers_section(entries): | |
| lines = "\n".join(f"- [[{slug}]] ({year}, {venue})" if venue else f"- [[{slug}]] ({year})" | |
| for slug, year, venue in entries) or "- (none currently)" | |
| return f"{MARK_A}\n## Papers in this vault\n\n{lines}\n{MARK_B}\n" | |
| def main() -> None: | |
| os.makedirs(AUTHORS_DIR, exist_ok=True) | |
| by_author = {} | |
| for path in glob.glob(os.path.join(VAULT, "papers", "*.md")) + glob.glob(os.path.join(VAULT, "influences", "*.md")): | |
| txt = open(path, encoding="utf-8").read() | |
| fm = txt.split("---")[1] | |
| m = re.search(r"^authors: \[(.*)\]$", fm, flags=re.M) | |
| if not m: | |
| continue | |
| slug = os.path.splitext(os.path.basename(path))[0] | |
| ym = re.search(r"^year:\s*(\d+)", fm, flags=re.M) | |
| vm = re.search(r'^venue:\s*"?(.*?)"?\s*$', fm, flags=re.M) | |
| year = ym.group(1) if ym else "?" | |
| venue = (vm.group(1) if vm else "")[:40] | |
| for name in re.findall(r"\[\[(.+?)\]\]", m.group(1)): | |
| by_author.setdefault(name, []).append((slug, year, venue)) | |
| names = set(by_author) | |
| created, refreshed = 0, 0 | |
| for name in sorted(names): | |
| entries = sorted(by_author[name], key=lambda e: (e[1], e[0])) # year, then slug: stable across machines | |
| section = papers_section(entries) | |
| out = os.path.join(AUTHORS_DIR, f"{name}.md") | |
| if not os.path.exists(out): | |
| with open(out, "w", encoding="utf-8") as f: | |
| f.write(STUB.format(name=name, papers_section=section)) | |
| created += 1 | |
| continue | |
| txt = open(out, encoding="utf-8").read() | |
| if MARK_A in txt and MARK_B in txt: | |
| new = re.sub(re.escape(MARK_A) + r".*?" + re.escape(MARK_B) + r"\n?", | |
| section, txt, flags=re.S) | |
| else: | |
| # legacy stub: replace the dataview papers section wholesale | |
| new = re.sub(r"## Papers in this vault\n+```dataview.*?```\n?", | |
| section, txt, flags=re.S) | |
| if new == txt: # enriched/unknown layout: append the generated section | |
| new = txt.rstrip() + "\n\n" + section | |
| if new != txt: | |
| open(out, "w", encoding="utf-8").write(new) | |
| refreshed += 1 | |
| # macOS may list filenames decomposed (NFD) while notes spell names composed | |
| # (NFC): compare in NFC so accented authors are not reported as stale. | |
| nfc = lambda s: unicodedata.normalize("NFC", s) | |
| existing = {nfc(os.path.splitext(f)[0]) for f in os.listdir(AUTHORS_DIR) if f.endswith(".md")} | |
| stale = existing - {nfc(n) for n in names} | |
| print(f"authors referenced: {len(names)}, notes created: {created}, link-sections refreshed: {refreshed}") | |
| if stale: | |
| print(f"notes no paper references (check spelling drift, not deleted): {sorted(stale)}") | |
| if __name__ == "__main__": | |
| main() | |