108 lines
5.7 KiB
Python
108 lines
5.7 KiB
Python
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"
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
def search(q, court=None, n=4):
|
|
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}"
|
|
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)
|
|
|
|
CASES = {
|
|
"Littlefield": ("wash", ["Littlefield commingle trace separate property",
|
|
"Littlefield \"clear and satisfactory\" evidence trace",
|
|
"Littlefield reverse commingling burden"]),
|
|
"Kovacs": ("wash", ["Kovacs marriage transmutation separate property",
|
|
"Kovacs marriage characterization acquisition",
|
|
"Kovacs marriage clear and convincing community"]),
|
|
"Chumbley": ("wash", ["Chumbley marriage separate contribution appreciation",
|
|
"Chumbley marriage tracing formula community interest",
|
|
"Chumbley marriage commingling acquisition"]),
|
|
"Short": ("wash", ["Short marriage transmutation separate property",
|
|
"Short marriage characterization 61176-9",
|
|
"Short marriage community presumption tracing"]),
|
|
"Borghi": ("wash", ["Borghi estate community property presumption",
|
|
"Borghi Gilroy separate property tracing",
|
|
"Borghi estate clear and convincing"]),
|
|
"Elam": ("wash", ["Elam marriage characterization acquisition gift",
|
|
"Elam marriage transmutation separate property",
|
|
"Elam marriage presumption community burden"]),
|
|
"Konzen": ("wash", ["Konzen marriage characterization acquisition date",
|
|
"Konzen marriage separate community funds",
|
|
"Konzen marriage transmutation"]),
|
|
"Skarbek": ("washctapp", ["Skarbek marriage transmutation inheritance",
|
|
"Skarbek marriage separate property intent",
|
|
"Skarbek marriage commingling community"]),
|
|
"PearsonMaines": ("washctapp", ["Pearson-Maines transmutation intent",
|
|
"Pearson-Maines separate property joint tenancy",
|
|
"Pearson-Maines marriage gift presumption"]),
|
|
"Olivares": ("washctapp", ["Olivares transmutation separate property",
|
|
"Olivares marriage joint tenancy intent",
|
|
"Olivares marriage characterization"]),
|
|
"Sedlock": ("washctapp", ["Sedlock transmutation community property",
|
|
"Sedlock marriage separate property agreement",
|
|
"Sedlock marriage characterization"]),
|
|
"Glorfield": ("washctapp", ["Glorfield transmutation separate property",
|
|
"Glorfield marriage community intent",
|
|
"Glorfield marriage characterization"]),
|
|
"Hadley": ("wash", ["Hadley marriage separate property division",
|
|
"Hadley marriage 88 Wash.2d 649",
|
|
"Hadley marriage just and equitable"]),
|
|
"Schwarz": ("washctapp", ["Schwarz v. Schwarz separate property mortgage community",
|
|
"Schwarz marriage commingling tracing",
|
|
"Schwarz marriage reimbursement community funds"]),
|
|
"Kraft": ("wash", ["Kraft marriage separate property division dissolution",
|
|
"Kraft marriage 119 Wash.2d 438",
|
|
"Kraft marriage exceptional circumstances"]),
|
|
"Berol": ("wash", ["Berol v. Berol transmutation community property",
|
|
"Berol separate property deed community",
|
|
"Berol v. Berol characterization"]),
|
|
"Brewer": ("wash", ["Brewer marriage separate property division",
|
|
"Brewer marriage just and equitable property",
|
|
"Brewer marriage 137 Wash.2d"]),
|
|
"Mueller": ("washctapp", ["Mueller marriage commingling trace separate",
|
|
"Mueller marriage \"clear and satisfactory\"",
|
|
"Mueller marriage Littlefield tracing"]),
|
|
}
|
|
|
|
allout = {}
|
|
for name, (court, queries) in CASES.items():
|
|
snippets = []
|
|
for q in queries:
|
|
d = search(q, court)
|
|
if "error" in d:
|
|
snippets.append({"q": q, "err": d["error"]})
|
|
continue
|
|
for res in d.get("results", []):
|
|
cn = (res.get("caseName") or "").lower()
|
|
if name.lower().split("maines")[0].split("schwarz")[0].split("berol")[0] not in cn and name.lower() not in cn:
|
|
continue
|
|
sn = res.get("opinions", [{}])[0].get("snippet", "")
|
|
if len(sn) > 200:
|
|
snippets.append({"q": q, "case": res.get("caseName"), "date": res.get("dateFiled"),
|
|
"cit": res.get("citation", [])[:2], "snip": sn})
|
|
break
|
|
time.sleep(2)
|
|
allout[name] = snippets
|
|
print(f"=== {name}: {len(snippets)} snippets")
|
|
for s in snippets[:3]:
|
|
if "err" in s:
|
|
print(" ERR", s["err"]); continue
|
|
print(" Q:", s["q"])
|
|
print(" ", s["case"], "|", s["date"], "|", s["cit"])
|
|
time.sleep(2)
|
|
|
|
json.dump(allout, open(f"{OUT}/harvest1.json", "w"), indent=1)
|
|
print("saved harvest1.json")
|