From da7733490f213542eb70c4695dd2b813adfae4b4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 23 Aug 2026 22:44:25 -0400 Subject: [PATCH] refactor hardcoded paths. --- scripts/twitter/README.md | 14 +++++++++----- scripts/twitter/graph_dry_run.py | 3 ++- scripts/twitter/lift_catbox.py | 5 +++-- scripts/twitter/paths.py | 13 +++++++++++++ scripts/twitter/tw.py | 19 ++++++++----------- 5 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 scripts/twitter/paths.py diff --git a/scripts/twitter/README.md b/scripts/twitter/README.md index d01d0e9..56e07da 100644 --- a/scripts/twitter/README.md +++ b/scripts/twitter/README.md @@ -2,14 +2,18 @@ Front door: `tw.py`. Individual scripts still work. +From the vault root: + ``` -python C:\projects\Threadwell\scripts\twitter\tw.py locate --id -python C:\projects\Threadwell\scripts\twitter\tw.py graph --id -python C:\projects\Threadwell\scripts\twitter\tw.py refresh --id --tip -python C:\projects\Threadwell\scripts\twitter\tw.py lift --id --orig -python C:\projects\Threadwell\scripts\twitter\tw.py ocr --id +python scripts/twitter/tw.py locate --id +python scripts/twitter/tw.py graph --id +python scripts/twitter/tw.py refresh --id --tip +python scripts/twitter/tw.py lift --id --orig +python scripts/twitter/tw.py ocr --id ``` +`paths.py` sets vault = two parents above this file, dumps = `../manual_slop/docs/twitter`, scratch = `../Threadwell-ai/scratch`. + `refresh` = refetch (cookies) + ingest + emit `--force` + media_merge. `--tip` treats `--id` as the tip (climb same-handle `reply_to`). Does not flip `draft`. Does not commit. Frozen Onat ids abort. Usual publish path after you like the note: diff --git a/scripts/twitter/graph_dry_run.py b/scripts/twitter/graph_dry_run.py index 389f196..09beac4 100644 --- a/scripts/twitter/graph_dry_run.py +++ b/scripts/twitter/graph_dry_run.py @@ -8,6 +8,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from twitter.models import load_thread +from twitter.paths import SCRATCH from twitter.slug import slugify from twitter.tree import branch_roots, by_id, children_map, descendants, spine_ids @@ -99,7 +100,7 @@ def main(argv: list[str] | None = None) -> int: thread = load_thread(path) text = render_ssdl(thread) + "\n\n" + render_ascii(thread) + "\n" out = args.input if args.input.is_dir() else args.input.parent - dest = Path(r"C:\projects\Threadwell-ai\scratch") / f"graph_{thread.root_post_id}.txt" + dest = SCRATCH / f"graph_{thread.root_post_id}.txt" dest.parent.mkdir(parents=True, exist_ok=True) dest.write_text(text, encoding="utf-8") sys.stdout.buffer.write((str(dest) + "\n").encode("ascii", "replace")) diff --git a/scripts/twitter/lift_catbox.py b/scripts/twitter/lift_catbox.py index 3db87fc..a8edb75 100644 --- a/scripts/twitter/lift_catbox.py +++ b/scripts/twitter/lift_catbox.py @@ -20,8 +20,9 @@ import sys import tomllib from pathlib import Path +from paths import VAULT as VAULT_ROOT + API = "https://catbox.moe/user/api.php" -CREDS = Path("secrets/credentials.toml") def load_userhash(vault: Path) -> str: @@ -98,7 +99,7 @@ def rewrite_notes(notes_dir: Path, old_tokens: list[str], url: str) -> int: def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--vault", type=Path, default=Path(r"C:\projects\Threadwell")) + parser.add_argument("--vault", type=Path, default=VAULT_ROOT) parser.add_argument("--thread", type=Path, required=True) parser.add_argument("--notes", type=Path, required=True) parser.add_argument( diff --git a/scripts/twitter/paths.py b/scripts/twitter/paths.py new file mode 100644 index 0000000..8841e40 --- /dev/null +++ b/scripts/twitter/paths.py @@ -0,0 +1,13 @@ +"""Repo-relative locations. Script lives at /scripts/twitter/.""" +from __future__ import annotations + +from pathlib import Path + +HERE = Path(__file__).resolve().parent +VAULT = HERE.parent.parent +PROJECTS = VAULT.parent +DUMPS = PROJECTS / "manual_slop" / "docs" / "twitter" +WORKSPACE = PROJECTS / "Threadwell-ai" +SCRATCH = WORKSPACE / "scratch" +COOKIES = VAULT / "secrets" / "twitter_cookies.txt" +FROZEN = HERE / "do_not_refetch.txt" diff --git a/scripts/twitter/tw.py b/scripts/twitter/tw.py index da8f4cd..685f342 100644 --- a/scripts/twitter/tw.py +++ b/scripts/twitter/tw.py @@ -1,10 +1,12 @@ """Front door for common Twitter archive ops. - python C:\\projects\\Threadwell\\scripts\\twitter\\tw.py graph --id 1692565070583136348 - python C:\\projects\\Threadwell\\scripts\\twitter\\tw.py refresh --id 1692565070583136348 --tip - python C:\\projects\\Threadwell\\scripts\\twitter\\tw.py lift --id 1692565070583136348 --orig - python C:\\projects\\Threadwell\\scripts\\twitter\\tw.py ocr --id 1692565070583136348 - python C:\\projects\\Threadwell\\scripts\\twitter\\tw.py locate --id 1692565070583136348 +From the vault root: + + python scripts/twitter/tw.py graph --id 1692565070583136348 + python scripts/twitter/tw.py refresh --id 1692565070583136348 --tip + python scripts/twitter/tw.py lift --id 1692565070583136348 --orig + python scripts/twitter/tw.py ocr --id 1692565070583136348 + python scripts/twitter/tw.py locate --id 1692565070583136348 refresh = refetch + emit --force (--tip uses the --id as tip). Does not commit. Does not flip draft. Never prints cookies or userhash. @@ -17,12 +19,7 @@ import subprocess import sys from pathlib import Path -HERE = Path(__file__).resolve().parent -VAULT = Path(r"C:\projects\Threadwell") -DUMPS = Path(r"C:\projects\manual_slop\docs\twitter") -SCRATCH = Path(r"C:\projects\Threadwell-ai\scratch") -COOKIES = VAULT / "secrets" / "twitter_cookies.txt" -FROZEN = HERE / "do_not_refetch.txt" +from paths import COOKIES, DUMPS, FROZEN, HERE, SCRATCH, VAULT def frozen_ids() -> set[str]: