@kinloom/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/cached-ocr.py +556 -0
- package/dist/assets/ocr.md +52 -0
- package/dist/assets/prep-scan.md +59 -0
- package/dist/assets/prep-scan.py +891 -0
- package/dist/bundled-skills/acpl-persi/SKILL.md +94 -0
- package/dist/bundled-skills/acpl-persi/scripts/persi +268 -0
- package/dist/bundled-skills/archive-org/SKILL.md +129 -0
- package/dist/bundled-skills/archive-org/scripts/archive-org +879 -0
- package/dist/bundled-skills/blm-glo/SKILL.md +54 -0
- package/dist/bundled-skills/california-archives/SKILL.md +120 -0
- package/dist/bundled-skills/california-archives/scripts/ca-archives +373 -0
- package/dist/bundled-skills/chronicling-america/SKILL.md +100 -0
- package/dist/bundled-skills/chronicling-america/scripts/chronam +250 -0
- package/dist/bundled-skills/cyndis-list/SKILL.md +53 -0
- package/dist/bundled-skills/findagrave/SKILL.md +116 -0
- package/dist/bundled-skills/findagrave/scripts/findagrave +520 -0
- package/dist/bundled-skills/hathitrust/SKILL.md +110 -0
- package/dist/bundled-skills/hathitrust/scripts/hathi +194 -0
- package/dist/bundled-skills/kentucky-archives/SKILL.md +123 -0
- package/dist/bundled-skills/kentucky-archives/scripts/ky-archives +358 -0
- package/dist/bundled-skills/library-of-michigan/SKILL.md +111 -0
- package/dist/bundled-skills/library-of-michigan/scripts/michiganology +346 -0
- package/dist/bundled-skills/missouri-archives/SKILL.md +100 -0
- package/dist/bundled-skills/missouri-archives/scripts/mo-archives +528 -0
- package/dist/bundled-skills/nara-catalog-search/SKILL.md +118 -0
- package/dist/bundled-skills/nara-catalog-search/scripts/nara +934 -0
- package/dist/bundled-skills/narrative-audio/SKILL.md +103 -0
- package/dist/bundled-skills/narrative-audio/references/script-rules.md +109 -0
- package/dist/bundled-skills/narrative-audio/scripts/narrative-audio +290 -0
- package/dist/bundled-skills/new-jersey-archives/SKILL.md +118 -0
- package/dist/bundled-skills/new-jersey-archives/scripts/nj-archives +585 -0
- package/dist/bundled-skills/openarchieven/SKILL.md +90 -0
- package/dist/bundled-skills/openarchieven/scripts/openarchieven +432 -0
- package/dist/bundled-skills/texas-archives/SKILL.md +93 -0
- package/dist/bundled-skills/texas-archives/scripts/texas-archives +441 -0
- package/dist/bundled-skills/uk-archives/SKILL.md +101 -0
- package/dist/bundled-skills/uk-archives/scripts/uk-archives +391 -0
- package/dist/bundled-skills/usgs-gnis/SKILL.md +89 -0
- package/dist/bundled-skills/usgs-gnis/scripts/gnis +254 -0
- package/dist/bundled-skills/virginia-archives/SKILL.md +104 -0
- package/dist/bundled-skills/virginia-archives/scripts/va-archives +466 -0
- package/dist/bundled-skills/wikitree/SKILL.md +148 -0
- package/dist/bundled-skills/wikitree/scripts/wikitree +219 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +383 -26
- package/dist/cli.js.map +1 -1
- package/dist/client.js +1 -1
- package/dist/commands/init.js +3 -3
- package/dist/commands/ops/audit.d.ts +138 -0
- package/dist/commands/ops/audit.d.ts.map +1 -0
- package/dist/commands/ops/audit.js +867 -0
- package/dist/commands/ops/audit.js.map +1 -0
- package/dist/commands/ops/context.d.ts +100 -0
- package/dist/commands/ops/context.d.ts.map +1 -0
- package/dist/commands/ops/context.js +917 -0
- package/dist/commands/ops/context.js.map +1 -0
- package/dist/commands/ops/help.d.ts +6 -0
- package/dist/commands/ops/help.d.ts.map +1 -0
- package/dist/commands/ops/help.js +74 -0
- package/dist/commands/ops/help.js.map +1 -0
- package/dist/commands/ops/index.d.ts +6 -0
- package/dist/commands/ops/index.d.ts.map +1 -0
- package/dist/commands/ops/index.js +6 -0
- package/dist/commands/ops/index.js.map +1 -0
- package/dist/commands/ops/integrate.d.ts +56 -0
- package/dist/commands/ops/integrate.d.ts.map +1 -0
- package/dist/commands/ops/integrate.js +872 -0
- package/dist/commands/ops/integrate.js.map +1 -0
- package/dist/commands/ops/sync.d.ts +177 -0
- package/dist/commands/ops/sync.d.ts.map +1 -0
- package/dist/commands/ops/sync.js +1078 -0
- package/dist/commands/ops/sync.js.map +1 -0
- package/dist/commands/ops/telemetry.d.ts +79 -0
- package/dist/commands/ops/telemetry.d.ts.map +1 -0
- package/dist/commands/ops/telemetry.js +249 -0
- package/dist/commands/ops/telemetry.js.map +1 -0
- package/dist/commands/records/help.d.ts +18 -0
- package/dist/commands/records/help.d.ts.map +1 -0
- package/dist/commands/records/help.js +174 -0
- package/dist/commands/records/help.js.map +1 -0
- package/dist/commands/records/index.d.ts +5 -0
- package/dist/commands/records/index.d.ts.map +1 -0
- package/dist/commands/records/index.js +5 -0
- package/dist/commands/records/index.js.map +1 -0
- package/dist/commands/records/registry.d.ts +32 -0
- package/dist/commands/records/registry.d.ts.map +1 -0
- package/dist/commands/records/registry.js +227 -0
- package/dist/commands/records/registry.js.map +1 -0
- package/dist/commands/records/resolve.d.ts +14 -0
- package/dist/commands/records/resolve.d.ts.map +1 -0
- package/dist/commands/records/resolve.js +61 -0
- package/dist/commands/records/resolve.js.map +1 -0
- package/dist/commands/records/runner.d.ts +25 -0
- package/dist/commands/records/runner.d.ts.map +1 -0
- package/dist/commands/records/runner.js +224 -0
- package/dist/commands/records/runner.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
#!/usr/bin/env -S uv run --script
|
|
2
|
+
# /// script
|
|
3
|
+
# requires-python = ">=3.11"
|
|
4
|
+
# dependencies = [
|
|
5
|
+
# "click>=8.1",
|
|
6
|
+
# "httpx>=0.27",
|
|
7
|
+
# ]
|
|
8
|
+
# ///
|
|
9
|
+
"""CLI for UK/England genealogy: TNA Discovery API and FreeREG parish registers.
|
|
10
|
+
|
|
11
|
+
Verified live 2026-11-24 with plain HTTP (no API key):
|
|
12
|
+
|
|
13
|
+
- Discovery search: GET discovery.nationalarchives.gov.uk/API/search/v1/records
|
|
14
|
+
with sps.searchQuery, optional sps.dateFrom / sps.dateTo (YYYY-MM-DD), rows.
|
|
15
|
+
- Discovery detail: GET .../API/records/v1/details/<id> (not .../search/v1/...).
|
|
16
|
+
- FreeREG: GET home page for CSRF token, POST /search_queries with
|
|
17
|
+
search_query[...] fields; results HTML at /search_queries/<id>.
|
|
18
|
+
|
|
19
|
+
Nottinghamshire Archives CalmView (nawcat.nottinghamshire.gov.uk) timed out
|
|
20
|
+
from this host (45s+); no machine search is wired. Use `url --notts`.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import html as html_mod
|
|
26
|
+
import json
|
|
27
|
+
import re
|
|
28
|
+
from urllib.parse import quote, urlencode, urljoin
|
|
29
|
+
|
|
30
|
+
import click
|
|
31
|
+
import httpx
|
|
32
|
+
|
|
33
|
+
DISCOVERY_SEARCH = "https://discovery.nationalarchives.gov.uk/API/search/v1/records"
|
|
34
|
+
DISCOVERY_DETAIL = "https://discovery.nationalarchives.gov.uk/API/records/v1/details"
|
|
35
|
+
DISCOVERY_WEB = "https://discovery.nationalarchives.gov.uk/details/r/"
|
|
36
|
+
FREEREG_BASE = "https://www.freereg.org.uk"
|
|
37
|
+
FREEREG_SEARCH = FREEREG_BASE + "/search_queries"
|
|
38
|
+
USER_AGENT = (
|
|
39
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
|
40
|
+
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Chapman county codes (FreeREG). Extend as needed.
|
|
44
|
+
CHAPMAN: dict[str, str] = {
|
|
45
|
+
"nottinghamshire": "NTT",
|
|
46
|
+
"ntt": "NTT",
|
|
47
|
+
"london": "LND",
|
|
48
|
+
"lnd": "LND",
|
|
49
|
+
"kent": "KEN",
|
|
50
|
+
"ken": "KEN",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
GENUKI_PARISHES: dict[str, str] = {
|
|
54
|
+
"england": "https://www.genuki.org.uk/big/eng",
|
|
55
|
+
"kent": "https://www.genuki.org.uk/big/eng/KEN",
|
|
56
|
+
"london": "https://www.genuki.org.uk/big/eng/LND",
|
|
57
|
+
"nottingham": "https://www.genuki.org.uk/big/eng/NTT/Nottingham",
|
|
58
|
+
"nottinghamshire": "https://www.genuki.org.uk/big/eng/NTT",
|
|
59
|
+
"yorkshire": "https://www.genuki.org.uk/big/eng/YKS",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _client() -> httpx.Client:
|
|
64
|
+
return httpx.Client(headers={"User-Agent": USER_AGENT}, timeout=90.0, follow_redirects=True)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _date_from(value: str | None) -> str | None:
|
|
68
|
+
if not value:
|
|
69
|
+
return None
|
|
70
|
+
value = value.strip()
|
|
71
|
+
if re.fullmatch(r"\d{4}", value):
|
|
72
|
+
return f"{value}-01-01"
|
|
73
|
+
return value
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _date_to(value: str | None) -> str | None:
|
|
77
|
+
if not value:
|
|
78
|
+
return None
|
|
79
|
+
value = value.strip()
|
|
80
|
+
if re.fullmatch(r"\d{4}", value):
|
|
81
|
+
return f"{value}-12-31"
|
|
82
|
+
return value
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _discovery_query(query: str, held_by: str | None, collection: str | None) -> str:
|
|
86
|
+
parts = [query.strip()]
|
|
87
|
+
if held_by:
|
|
88
|
+
parts.append(held_by.strip())
|
|
89
|
+
if collection:
|
|
90
|
+
parts.append(f'"{collection.strip()}"')
|
|
91
|
+
return " ".join(p for p in parts if p)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _discovery_hit(rec: dict) -> dict:
|
|
95
|
+
rec_id = rec.get("id") or ""
|
|
96
|
+
ref = rec.get("reference") or ""
|
|
97
|
+
return {
|
|
98
|
+
"id": rec_id,
|
|
99
|
+
"reference": ref,
|
|
100
|
+
"title": rec.get("title") or "",
|
|
101
|
+
"description": rec.get("description") or "",
|
|
102
|
+
"covering_dates": rec.get("coveringDates") or "",
|
|
103
|
+
"department": rec.get("department") or "",
|
|
104
|
+
"places": rec.get("places") or [],
|
|
105
|
+
"held_by": rec.get("heldBy") or [],
|
|
106
|
+
"record_url": DISCOVERY_WEB + rec_id if rec_id else "",
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _collection_match(rec: dict, collection: str) -> bool:
|
|
111
|
+
coll = collection.strip()
|
|
112
|
+
ref = rec.get("reference") or ""
|
|
113
|
+
if coll.upper().startswith("PROB"):
|
|
114
|
+
return ref.upper().startswith(coll.upper())
|
|
115
|
+
return coll.upper() in ref.upper() or coll.upper() in (rec.get("title") or "").upper()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _discovery_detail_payload(raw: dict) -> dict:
|
|
119
|
+
scope = raw.get("scopeContent") or {}
|
|
120
|
+
desc = scope.get("description") if isinstance(scope, dict) else None
|
|
121
|
+
if desc and isinstance(desc, str):
|
|
122
|
+
desc = re.sub(r"<[^>]+>", " ", html_mod.unescape(desc))
|
|
123
|
+
desc = re.sub(r"\s+", " ", desc).strip()
|
|
124
|
+
held = raw.get("heldBy") or []
|
|
125
|
+
held_names = []
|
|
126
|
+
for item in held:
|
|
127
|
+
if isinstance(item, dict):
|
|
128
|
+
held_names.append(item.get("xReferenceName") or item.get("name") or "")
|
|
129
|
+
elif isinstance(item, str):
|
|
130
|
+
held_names.append(item)
|
|
131
|
+
return {
|
|
132
|
+
"id": raw.get("id"),
|
|
133
|
+
"citable_reference": raw.get("citableReference") or raw.get("referencePart"),
|
|
134
|
+
"covering_dates": raw.get("coveringDates"),
|
|
135
|
+
"description": desc,
|
|
136
|
+
"held_by": [h for h in held_names if h],
|
|
137
|
+
"digitised": raw.get("digitised"),
|
|
138
|
+
"legal_status": raw.get("legalStatus"),
|
|
139
|
+
"catalogue_level": raw.get("catalogueLevel"),
|
|
140
|
+
"record_url": DISCOVERY_WEB + (raw.get("id") or ""),
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _freereg_token(html: str) -> str:
|
|
145
|
+
m = re.search(r'name="authenticity_token" value="([^"]+)"', html)
|
|
146
|
+
if not m:
|
|
147
|
+
raise click.ClickException("FreeREG authenticity_token not found (page layout may have changed).")
|
|
148
|
+
return m.group(1)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def parse_freereg_results(page: str) -> list[dict]:
|
|
152
|
+
"""Parse FreeREG search results table rows."""
|
|
153
|
+
tbody = re.search(r"<tbody>(.*?)</tbody>", page, re.S | re.I)
|
|
154
|
+
if not tbody:
|
|
155
|
+
return []
|
|
156
|
+
out: list[dict] = []
|
|
157
|
+
for tr in re.finditer(r'<tr id="([^"]+)"[^>]*>(.*?)</tr>', tbody.group(1), re.S | re.I):
|
|
158
|
+
row_id = tr.group(1)
|
|
159
|
+
inner = tr.group(2)
|
|
160
|
+
link_m = re.search(r'href="([^"]+)"[^>]*>\s*View\s*\d+', inner, re.I)
|
|
161
|
+
path = link_m.group(1) if link_m else ""
|
|
162
|
+
cells = re.findall(r"<td[^>]*>(.*?)</td>", inner, re.S | re.I)
|
|
163
|
+
if len(cells) < 5:
|
|
164
|
+
continue
|
|
165
|
+
clean = []
|
|
166
|
+
for c in cells[1:]:
|
|
167
|
+
text = html_mod.unescape(re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", c))).strip()
|
|
168
|
+
clean.append(text)
|
|
169
|
+
persons, record_type, event_date, county, register = (clean + [""] * 5)[:5]
|
|
170
|
+
out.append({
|
|
171
|
+
"transcript_id": row_id,
|
|
172
|
+
"persons": persons,
|
|
173
|
+
"record_type": record_type,
|
|
174
|
+
"event_date": event_date,
|
|
175
|
+
"county": county,
|
|
176
|
+
"register": register,
|
|
177
|
+
"transcript_url": urljoin(FREEREG_BASE, path) if path else "",
|
|
178
|
+
})
|
|
179
|
+
return out
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
|
|
183
|
+
def cli() -> None:
|
|
184
|
+
"""Search UK archives: TNA Discovery and FreeREG parish registers."""
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@cli.group("discovery")
|
|
188
|
+
def discovery() -> None:
|
|
189
|
+
"""The National Archives Discovery catalogue (free JSON API)."""
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@discovery.command("search")
|
|
193
|
+
@click.argument("query")
|
|
194
|
+
@click.option("--held-by", default=None, help="Extra text added to the query (e.g. Nottinghamshire).")
|
|
195
|
+
@click.option("--date-from", "date_from", default=None, help="Covering date from (YYYY or YYYY-MM-DD).")
|
|
196
|
+
@click.option("--date-to", "date_to", default=None, help="Covering date to (YYYY or YYYY-MM-DD).")
|
|
197
|
+
@click.option(
|
|
198
|
+
"--collection",
|
|
199
|
+
default=None,
|
|
200
|
+
help='Filter hits whose reference/title match this string (e.g. PROB 11). Also appended to the query.',
|
|
201
|
+
)
|
|
202
|
+
@click.option("--limit", default=10, show_default=True, type=int, help="Maximum records to return (API rows).")
|
|
203
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
204
|
+
def cmd_discovery_search(
|
|
205
|
+
query: str,
|
|
206
|
+
held_by: str | None,
|
|
207
|
+
date_from: str | None,
|
|
208
|
+
date_to: str | None,
|
|
209
|
+
collection: str | None,
|
|
210
|
+
limit: int,
|
|
211
|
+
as_json: bool,
|
|
212
|
+
) -> None:
|
|
213
|
+
"""Search Discovery for catalogue records."""
|
|
214
|
+
q = _discovery_query(query, held_by, collection)
|
|
215
|
+
params: dict[str, str | int] = {"sps.searchQuery": q, "rows": min(max(limit, 1), 100)}
|
|
216
|
+
df = _date_from(date_from)
|
|
217
|
+
dt = _date_to(date_to)
|
|
218
|
+
if df:
|
|
219
|
+
params["sps.dateFrom"] = df
|
|
220
|
+
if dt:
|
|
221
|
+
params["sps.dateTo"] = dt
|
|
222
|
+
with _client() as c:
|
|
223
|
+
resp = c.get(DISCOVERY_SEARCH, params=params)
|
|
224
|
+
resp.raise_for_status()
|
|
225
|
+
data = resp.json()
|
|
226
|
+
records = [_discovery_hit(r) for r in data.get("records") or []]
|
|
227
|
+
if collection:
|
|
228
|
+
records = [r for r in records if _collection_match(
|
|
229
|
+
{"reference": r["reference"], "department": r["department"], "title": r["title"]},
|
|
230
|
+
collection,
|
|
231
|
+
)]
|
|
232
|
+
records = records[:limit]
|
|
233
|
+
total = data.get("count", len(records))
|
|
234
|
+
if as_json:
|
|
235
|
+
click.echo(json.dumps({"query": q, "total": total, "returned": len(records), "records": records}, indent=1))
|
|
236
|
+
return
|
|
237
|
+
click.echo(f'{total} hit(s) for "{q}"; showing {len(records)}:')
|
|
238
|
+
for rec in records:
|
|
239
|
+
places = ", ".join(rec["places"]) if rec["places"] else ""
|
|
240
|
+
click.echo(f'{rec["id"]} {rec["reference"]} {rec["covering_dates"]}')
|
|
241
|
+
click.echo(f' {rec["title"]}')
|
|
242
|
+
if places:
|
|
243
|
+
click.echo(f" Places: {places}")
|
|
244
|
+
click.echo(f" {rec['record_url']}")
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
@discovery.command("detail")
|
|
248
|
+
@click.argument("record_id")
|
|
249
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
250
|
+
def cmd_discovery_detail(record_id: str, as_json: bool) -> None:
|
|
251
|
+
"""Fetch one Discovery record by id (e.g. <record-id>)."""
|
|
252
|
+
url = f"{DISCOVERY_DETAIL}/{record_id}"
|
|
253
|
+
with _client() as c:
|
|
254
|
+
resp = c.get(url)
|
|
255
|
+
resp.raise_for_status()
|
|
256
|
+
raw = resp.json()
|
|
257
|
+
detail = _discovery_detail_payload(raw)
|
|
258
|
+
if as_json:
|
|
259
|
+
click.echo(json.dumps(detail, indent=1))
|
|
260
|
+
return
|
|
261
|
+
click.echo(f'{detail["id"]} {detail["citable_reference"]} {detail["covering_dates"]}')
|
|
262
|
+
if detail["description"]:
|
|
263
|
+
click.echo(f' {detail["description"]}')
|
|
264
|
+
if detail["held_by"]:
|
|
265
|
+
click.echo(" Held by: " + "; ".join(detail["held_by"]))
|
|
266
|
+
click.echo(f' Digitised: {detail["digitised"]} Legal status: {detail["legal_status"] or "n/a"}')
|
|
267
|
+
click.echo(f' {detail["record_url"]}')
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
@cli.group("freereg")
|
|
271
|
+
def freereg() -> None:
|
|
272
|
+
"""FreeREG parish register transcriptions (Rails form POST, no API key)."""
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@freereg.command("search")
|
|
276
|
+
@click.option("--surname", required=True, help="Last name (required).")
|
|
277
|
+
@click.option("--given", default=None, help="First name.")
|
|
278
|
+
@click.option(
|
|
279
|
+
"--county",
|
|
280
|
+
default="NTT",
|
|
281
|
+
show_default=True,
|
|
282
|
+
help="Chapman county code or name (e.g. NTT / nottinghamshire).",
|
|
283
|
+
)
|
|
284
|
+
@click.option("--from-year", "from_year", default=None, help="Start year (YYYY).")
|
|
285
|
+
@click.option("--to-year", "to_year", default=None, help="End year (YYYY).")
|
|
286
|
+
@click.option(
|
|
287
|
+
"--record-type",
|
|
288
|
+
"record_type",
|
|
289
|
+
type=click.Choice(["all", "baptism", "marriage", "burial"], case_sensitive=False),
|
|
290
|
+
default="all",
|
|
291
|
+
show_default=True,
|
|
292
|
+
)
|
|
293
|
+
@click.option("--place-contains", default=None, help="Keep only hits whose register column contains this text.")
|
|
294
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
295
|
+
def cmd_freereg_search(
|
|
296
|
+
surname: str,
|
|
297
|
+
given: str | None,
|
|
298
|
+
county: str,
|
|
299
|
+
from_year: str | None,
|
|
300
|
+
to_year: str | None,
|
|
301
|
+
record_type: str,
|
|
302
|
+
place_contains: str | None,
|
|
303
|
+
as_json: bool,
|
|
304
|
+
) -> None:
|
|
305
|
+
"""Search FreeREG parish register transcriptions."""
|
|
306
|
+
chapman = CHAPMAN.get(county.strip().lower(), county.strip().upper())
|
|
307
|
+
rt_map = {"all": "", "baptism": "ba", "marriage": "ma", "burial": "bu"}
|
|
308
|
+
data: dict[str, str] = {
|
|
309
|
+
"utf8": "✓",
|
|
310
|
+
"search_query[last_name]": surname,
|
|
311
|
+
"search_query[chapman_codes][]": chapman,
|
|
312
|
+
"commit": "Search",
|
|
313
|
+
}
|
|
314
|
+
if given:
|
|
315
|
+
data["search_query[first_name]"] = given
|
|
316
|
+
if from_year:
|
|
317
|
+
data["search_query[start_year]"] = from_year
|
|
318
|
+
if to_year:
|
|
319
|
+
data["search_query[end_year]"] = to_year
|
|
320
|
+
rt = rt_map[record_type]
|
|
321
|
+
if rt:
|
|
322
|
+
data["search_query[record_type]"] = rt
|
|
323
|
+
with _client() as c:
|
|
324
|
+
home = c.get(FREEREG_BASE + "/")
|
|
325
|
+
home.raise_for_status()
|
|
326
|
+
data["authenticity_token"] = _freereg_token(home.text)
|
|
327
|
+
resp = c.post(FREEREG_SEARCH, data=data)
|
|
328
|
+
resp.raise_for_status()
|
|
329
|
+
records = parse_freereg_results(resp.text)
|
|
330
|
+
if place_contains:
|
|
331
|
+
needle = place_contains.lower()
|
|
332
|
+
records = [r for r in records if needle in r["register"].lower()]
|
|
333
|
+
if as_json:
|
|
334
|
+
click.echo(json.dumps({"surname": surname, "county": chapman, "returned": len(records), "records": records}, indent=1))
|
|
335
|
+
return
|
|
336
|
+
click.echo(f"{len(records)} FreeREG hit(s) for {surname} ({chapman}):")
|
|
337
|
+
for rec in records:
|
|
338
|
+
click.echo(f'{rec["event_date"]} {rec["record_type"]} {rec["persons"]}')
|
|
339
|
+
click.echo(f' {rec["register"]} ({rec["county"]})')
|
|
340
|
+
if rec["transcript_url"]:
|
|
341
|
+
click.echo(f' {rec["transcript_url"]}')
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
@cli.command("url")
|
|
345
|
+
@click.option("--discovery", "discovery_query", default=None, help="Discovery web search URL for a query.")
|
|
346
|
+
@click.option("--freereg", is_flag=True, help="FreeREG search form home.")
|
|
347
|
+
@click.option("--notts", "notts_query", default=None, help="Nottinghamshire Archives CalmView search hint (browser).")
|
|
348
|
+
@click.option("--bho", "bho_query", default=None, help="British History Online search query.")
|
|
349
|
+
@click.option(
|
|
350
|
+
"--genuki",
|
|
351
|
+
type=click.Choice(list(GENUKI_PARISHES.keys())),
|
|
352
|
+
default=None,
|
|
353
|
+
help="GENUKI county/parish page for England research.",
|
|
354
|
+
)
|
|
355
|
+
def cmd_url(
|
|
356
|
+
discovery_query: str | None,
|
|
357
|
+
freereg: bool,
|
|
358
|
+
notts_query: str | None,
|
|
359
|
+
bho_query: str | None,
|
|
360
|
+
genuki: str | None,
|
|
361
|
+
) -> None:
|
|
362
|
+
"""Print verified portal URLs (no search is run)."""
|
|
363
|
+
if discovery_query:
|
|
364
|
+
click.echo(
|
|
365
|
+
"https://discovery.nationalarchives.gov.uk/results/r?"
|
|
366
|
+
+ urlencode({"_q": discovery_query, "_p": 100}, quote_via=quote)
|
|
367
|
+
)
|
|
368
|
+
if freereg:
|
|
369
|
+
click.echo(FREEREG_BASE + "/")
|
|
370
|
+
if notts_query is not None:
|
|
371
|
+
click.echo("https://nawcat.nottinghamshire.gov.uk/CalmView/")
|
|
372
|
+
click.echo(
|
|
373
|
+
" (browser-only: HTTPS to nawcat timed out after 45s in automated checks; "
|
|
374
|
+
f"search in CalmView for: {notts_query or 'Lincoln'})"
|
|
375
|
+
)
|
|
376
|
+
if bho_query:
|
|
377
|
+
click.echo(
|
|
378
|
+
"https://www.british-history.ac.uk/search?"
|
|
379
|
+
+ urlencode({"query": bho_query})
|
|
380
|
+
)
|
|
381
|
+
if genuki:
|
|
382
|
+
click.echo(GENUKI_PARISHES[genuki])
|
|
383
|
+
if not any([discovery_query, freereg, notts_query is not None, bho_query, genuki]):
|
|
384
|
+
click.echo(DISCOVERY_WEB.rstrip("/"))
|
|
385
|
+
click.echo(FREEREG_BASE + "/")
|
|
386
|
+
click.echo("https://www.british-history.ac.uk/")
|
|
387
|
+
click.echo(GENUKI_PARISHES["nottinghamshire"])
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
if __name__ == "__main__":
|
|
391
|
+
cli()
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: usgs-gnis
|
|
3
|
+
description: Look up historical and current U.S. place names in the USGS Geographic Names Information System (GNIS) via the bundled uv-based `gnis` CLI or the GNIS Domestic Names Search web app. Covers cached per-state bulk downloads, feature-name search, feature classes, coordinates, and defunct places. Use when a deed, memoir, or obituary names a place that no longer exists, or to pin a migration path to exact coordinates.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# USGS GNIS (Geographic Names Information System)
|
|
7
|
+
|
|
8
|
+
This skill includes a standalone executable Python CLI at `skills/usgs-gnis/scripts/gnis` using a PEP 723 `#!/usr/bin/env -S uv run --script` shebang with inline dependencies (`click`, `httpx`). No virtualenv setup or API key is required.
|
|
9
|
+
|
|
10
|
+
- **What GNIS is:** the federal repository of official geographic names for the U.S., its territories, and Antarctica: natural features, populated places, post offices, schools, cemeteries, churches, and more, current and historical.
|
|
11
|
+
- **Access route:** there is **no documented public GNIS search API**. The GNIS Domestic Names Search web app is a JavaScript app whose backing services use authenticated tokens. The verified machine interface is the USGS staged-products bulk download (public S3, no key): per-state pipe-delimited text files plus national topical files. The CLI downloads a state file once, caches it, and searches locally.
|
|
12
|
+
- **Refresh cadence:** USGS refreshes the downloadable names data every other month.
|
|
13
|
+
|
|
14
|
+
## Bundled CLI (`scripts/gnis`)
|
|
15
|
+
|
|
16
|
+
Path: `skills/usgs-gnis/scripts/gnis`
|
|
17
|
+
|
|
18
|
+
### Download a state file
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Cache Illinois
|
|
22
|
+
skills/usgs-gnis/scripts/gnis download IL
|
|
23
|
+
|
|
24
|
+
# Cache California (about 2.7 MB zipped)
|
|
25
|
+
skills/usgs-gnis/scripts/gnis download CA
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Files land in `~/.cache/kinloom-gnis/<STATE>.txt` (override with `GNIS_CACHE_DIR`).
|
|
29
|
+
|
|
30
|
+
### Search feature names
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Any feature in Illinois with "New Salem" in the name
|
|
34
|
+
skills/usgs-gnis/scripts/gnis search "New Salem" --state IL
|
|
35
|
+
|
|
36
|
+
# Exact name match, populated places only, in Sangamon County
|
|
37
|
+
skills/usgs-gnis/scripts/gnis search Springfield --state IL --exact --class "Populated Place" --county Sangamon
|
|
38
|
+
|
|
39
|
+
# JSON output for scripting
|
|
40
|
+
skills/usgs-gnis/scripts/gnis search Hannibal --state MO --json
|
|
41
|
+
|
|
42
|
+
# Defunct places (historical features file, national, downloaded on demand)
|
|
43
|
+
skills/usgs-gnis/scripts/gnis search "New Salem" --historical
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Search matches on `feature_name` (substring unless `--exact`). Output gives the GNIS feature ID, name, class, county, state, decimal latitude/longitude, and map name.
|
|
47
|
+
|
|
48
|
+
### Look up one feature by ID
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
skills/usgs-gnis/scripts/gnis get <feature-id> --state IL
|
|
52
|
+
skills/usgs-gnis/scripts/gnis get <feature-id> --state MO --json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Open the web search app
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
skills/usgs-gnis/scripts/gnis url "New Salem"
|
|
59
|
+
# Prints https://edits.nationalmap.gov/apps/gaz-domestic/public/search/names
|
|
60
|
+
# (the app has no stable query-string search URL; enter the name by hand)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Website & download rules (verified live 2026-11-24)
|
|
64
|
+
|
|
65
|
+
- GNIS search app: `https://edits.nationalmap.gov/apps/gaz-domestic/public/search/names` (200, React app v2.3.1). From the app, up to 2,000 features may be downloaded to CSV. No sign-in is needed for public search.
|
|
66
|
+
- Downloads index: `https://www.usgs.gov/us-board-on-geographic-names/download-gnis-data`
|
|
67
|
+
- Per-state files: `https://prd-tnm.s3.amazonaws.com/StagedProducts/GeographicNames/DomesticNames/DomesticNames_<ST>_Text.zip`, where `<ST>` is the two-letter state/territory code (AK, AL, ..., WY, plus AS, DC, GU, MP, PR, VI). Verified: MI zip 1,014,149 bytes, CA zip 2,695,362 bytes.
|
|
68
|
+
- National topical files under `StagedProducts/GeographicNames/Topical/`, including `HistoricalFeatures_National_Text.zip` (defunct features), `AllNames_National_Text.zip`, `PopulatedPlaces_National_Text.zip`, `GovernmentUnits_National_Text.zip`, `FeatureDescriptionHistory_National_Text.zip`.
|
|
69
|
+
- File format (verified against live state files): a zip containing one pipe-delimited `.txt` with header `feature_id|feature_name|feature_class|state_name|state_numeric|county_name|county_numeric|map_name|date_created|date_edited|bgn_type|bgn_authority|bgn_date|prim_lat_dms|prim_long_dms|prim_lat_dec|prim_long_dec|source_lat_dms|source_long_dms|source_lat_dec|source_long_dec`. Full column documentation: `https://prd-tnm.s3.amazonaws.com/StagedProducts/GeographicNames/GNIS_file_format.pdf`.
|
|
70
|
+
- **Coordinates:** use `prim_lat_dec` / `prim_long_dec` (primary location). `source_*` coordinates are where the name was sourced, and can differ. Some rows carry `0.0, 0.0` for source coordinates; treat those as absent, not as a real location.
|
|
71
|
+
- **State files are not perfectly state-scoped:** border quads can include neighboring-state rows. Always check the `state_name` field on a hit, and filter by county.
|
|
72
|
+
- **No API key, no account.** The S3 downloads and the search app are public.
|
|
73
|
+
|
|
74
|
+
### What was checked and not found
|
|
75
|
+
|
|
76
|
+
- The app's JavaScript bundle (`/apps/gaz-domestic/assets/index-*.js`, ~3.8 MB) was inspected 2026-11-24: `search/names` is only a client-side route, and no public `/api` search endpoint is exposed. The app's config (`env-config.js`) shows it uses secure tokens and DOI login for editing. Do not build against undocumented app endpoints; use the bulk downloads.
|
|
77
|
+
- The older USGS Search API (a JavaScript location-search widget library from the Texas Water Science Center) is a web widget, not a GNIS query API, and was not used.
|
|
78
|
+
|
|
79
|
+
## Environment variables
|
|
80
|
+
|
|
81
|
+
- `GNIS_CACHE_DIR`: where state text files are cached (default `~/.cache/kinloom-gnis`).
|
|
82
|
+
|
|
83
|
+
## Research workflow notes
|
|
84
|
+
|
|
85
|
+
- Start from the place as written in the source (deed, memoir, obituary), then check GNIS for the current name, variant names, feature class, and county: county boundaries and names change, and the county on a hit is the modern one.
|
|
86
|
+
- **Civil townships vs populated places:** rural townships are indexed with the suffix `"Township"` under feature class `Civil` (not `Populated Place`). When searching for a township name, omit `--exact` and `--class "Populated Place"`, or pass `--class Civil`.
|
|
87
|
+
- Defunct post offices and railroad stops usually appear as `Post Office` / `Locale` / historical features; if a state-file search comes up empty, retry with `--historical`.
|
|
88
|
+
- Record the GNIS `feature_id` alongside any place you cite in `data/`: it is the stable identifier when names collide (there are many repeated place names across states).
|
|
89
|
+
- Coordinates from GNIS place a feature, not a parcel. For the parcel itself, pair the GNIS hit with the BLM GLO patent's township/range/section (see the `blm-glo` skill).
|