#!/usr/bin/env python3 """Search the awesome-reverse-engineered index and fetch a project. Usage: re_index.py search [--category TEXT] [--lang NAME] [--min-stars N] [--include-archived] [--limit N] [--json] re_index.py info # index entry + README excerpt re_index.py clone [--dest DIR] re_index.py categories Data source, first that works: $RE_INDEX_DATA (a local entries.json), a cache in ~/.cache/awesome-reverse-engineered (refreshed every 24 h from GitHub), the data/entries.json of the repo this script ships in. Standard library only. """ import argparse, json, math, os, re, subprocess, sys, time, urllib.request REPO = "alexgaoth/awesome-reverse-engineered" RAW = f"https://raw.githubusercontent.com/{REPO}/main/data/entries.json" CACHE = os.path.expanduser("~/.cache/awesome-reverse-engineered/entries.json") BUNDLED = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", "..", "data", "entries.json") SYNONYMS = { "twitter": ["x"], "x": ["twitter"], "ble": ["bluetooth"], "bluetooth": ["ble"], "car": ["vehicle", "automotive"], "vehicle": ["car"], "decomp": ["decompilation"], "decompile": ["decompilation"], "chatgpt": ["openai"], "openai": ["chatgpt"], "gemini": ["bard"], "instagram": ["meta"], "facebook": ["meta"], "imessage": ["apple"], "n64": ["nintendo 64"], "gamecube": ["gc"], "ps1": ["playstation 1", "psx"], "ps2": ["playstation 2"], "local": ["local control", "cloud-free"], "vacuum": ["robot"], } def load(): path = os.environ.get("RE_INDEX_DATA") if path: return json.load(open(path)) fresh = os.path.exists(CACHE) and time.time() - os.path.getmtime(CACHE) < 86400 if not fresh: try: with urllib.request.urlopen(RAW, timeout=20) as r: data = r.read() os.makedirs(os.path.dirname(CACHE), exist_ok=True) open(CACHE, "wb").write(data) except Exception as ex: print(f"note: could not refresh index ({ex}); using local copy", file=sys.stderr) for p in (CACHE, BUNDLED): if os.path.exists(p): return json.load(open(p)) sys.exit("error: no index data found (no network and no local data/entries.json)") def fields(e): slug = e["url"].rstrip("/").split("/")[-1] return [ (3.0, e["name"].lower()), (3.0, slug.lower().replace("-", " ").replace("_", " ")), (2.0, " ".join(e.get("topics") or []).lower().replace("-", " ")), (1.5, e.get("desc", "").lower()), (1.0, e.get("subcategory", "").lower()), (1.0, e.get("category", "").lower()), (1.0, (e.get("platform") or "").lower()), ] def hit(term, text): if len(term) <= 3: return re.search(rf"(?