import json, urllib.request, urllib.parse, time, os UA = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"} OUT = "/Users/drjones/astraea-books/.case-verify/snippets" def search(q, court=None, after=None, before=None, n=6): qq = urllib.parse.quote(q) url = f"https://www.courtlistener.com/api/rest/v4/search/?q={qq}&type=o&format=json" if court: url += f"&court={court}" if after: url += f"&filed_after={after}" if before: url += f"&filed_before={before}" for i in range(4): try: req = urllib.request.Request(url, headers=UA) with urllib.request.urlopen(req, timeout=40) as r: return json.loads(r.read()) except Exception as e: if i == 3: return {"error": str(e)} time.sleep(5 + i * 5) # (name, court, after, before, queries, target_substring) CASES = { "Littlefield_own": ("wash", "1997-01-01", "1997-12-31", ['"burden of proving" commingling', '"trace" "separate property" commingled', '"clear and satisfactory" evidence'], "littlefield"), "Littlefield_cited": ("washctapp", "2010-01-01", "2026-12-31", ['"Littlefield" commingling tracing separate'], "littlefield"), "Kovacs_own": ("wash", "1993-01-01", "1993-12-31", ['transmutation "joint tenancy"', '"clear and convincing" transmutation', '"source of funds" acquisition'], "kovacs"), "Kovacs_cited": ("wash", "2000-01-01", "2026-12-31", ['"Kovacs" transmutation'], "kovacs"), "Short_own": ("wash", "1995-01-01", "1995-12-31", ['"transmutation" Short 61176', '"separate property" commingled account'], "short"), "Short_cited": ("wash", "2000-01-01", "2026-12-31", ['"In re Marriage of Short"'], "short"), "Elam_own": ("wash", "1982-01-01", "1982-12-31", ['"gift" "community property" presumption acquisition', '"clear and convincing evidence" rebut'], "elam"), "Konzen_own": ("wash", "1985-01-01", "1985-12-31", ['"date of acquisition" separate community'], "konzen"), "Mueller_own": ("washctapp", "2007-01-01", "2007-12-31", ['commingling "reasonable certainty"', '"clear and satisfactory" trace separate'], "mueller"), "Glorfield_own": ("washctapp", "1980-01-01", "1980-12-31", ['transmutation community intent'], "glorfield"), "PearsonM_own": ("washctapp", "1993-01-01", "1993-12-31", ['"transmutation" separate property community'], "pearson-maines"), "Olivares_own": ("washctapp", "1993-01-01", "1993-12-31", ['"transmutation"', '"joint tenancy" separate'], "olivares"), "Sedlock_own": ("washctapp", "1993-01-01", "1993-12-31", ['"transmutation"', '"changed its character"'], "sedlock"), "Hadley_cited": ("wash", "1990-01-01", "2026-12-31", ['"Hadley" separate property division'], "hadley"), "Kraft_cited": ("washctapp", "2010-01-01", "2026-12-31", ['"Kraft" separate property "economic circumstances"'], "kraft"), "Berol_own": ("wash", "1950-01-01", "1950-12-31", ['"presumption" community deed Berol'], "berol"), } allout = {} for name, (court, after, before, queries, target) in CASES.items(): snips = [] for q in queries: d = search(q, court, after, before) if "error" in d: snips.append({"q": q, "err": d["error"]}); continue for res in d.get("results", []): cn = (res.get("caseName") or "").lower() sn = res.get("opinions", [{}])[0].get("snippet", "") if len(sn) > 200: snips.append({"q": q, "case": res.get("caseName"), "date": res.get("dateFiled"), "cit": res.get("citation", [])[:2], "snip": sn}) break time.sleep(2) allout[name] = snips print(f"=== {name}: {len(snips)}") for s in snips: if "err" in s: print(" ERR", s["err"]); continue print(" Q:", s["q"], "|", s["case"], "|", s["date"]) time.sleep(2) json.dump(allout, open(f"{OUT}/harvest3.json", "w"), indent=1) print("saved harvest3.json")