@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,441 @@
|
|
|
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
|
+
"""texas-archives: search Texas genealogy portals from the command line.
|
|
10
|
+
|
|
11
|
+
Verified live 2026-11-24. No account or API key is needed
|
|
12
|
+
for any command.
|
|
13
|
+
|
|
14
|
+
Machine interfaces:
|
|
15
|
+
|
|
16
|
+
- Portal to Texas History (UNT): OpenSearch JSON at
|
|
17
|
+
``GET https://texashistory.unt.edu/search/opensearch/?q=<query>&format=json``
|
|
18
|
+
(100 hits per page, ``pw`` for page). Item metadata via OAI-PMH
|
|
19
|
+
``GetRecord`` with ``identifier=ark:/67531/<id>``.
|
|
20
|
+
The HTML search UI and item/scan views redirect through an ALTCHA
|
|
21
|
+
challenge; plain HTTP cannot open them.
|
|
22
|
+
|
|
23
|
+
- Texas Digital Archive (TSLAC / Preservica): WordPress search RSS feed at
|
|
24
|
+
``GET https://tsl.access.preservica.com/search/<term>/feed/rss2/``
|
|
25
|
+
(fetched with curl; httpx gets HTTP 403 on this host).
|
|
26
|
+
|
|
27
|
+
Browser-only (use the ``url`` command):
|
|
28
|
+
|
|
29
|
+
- Portal item pages, page images, and OCR downloads (ALTCHA).
|
|
30
|
+
- Texas General Land Office Land Grant Search (``s3.glo.texas.gov``):
|
|
31
|
+
Salesforce/SPA shell; POST did not return parseable results live.
|
|
32
|
+
- Texas Ranger muster rolls and some TSLAC indexes (mail or reading room).
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from __future__ import annotations
|
|
36
|
+
|
|
37
|
+
import html as htmlmod
|
|
38
|
+
import json
|
|
39
|
+
import re
|
|
40
|
+
import subprocess
|
|
41
|
+
import xml.etree.ElementTree as ET
|
|
42
|
+
from datetime import date
|
|
43
|
+
from urllib.parse import quote, urlencode
|
|
44
|
+
|
|
45
|
+
import click
|
|
46
|
+
import httpx
|
|
47
|
+
|
|
48
|
+
PORTAL_BASE = "https://texashistory.unt.edu"
|
|
49
|
+
PORTAL_OPENSEARCH = PORTAL_BASE + "/search/opensearch/"
|
|
50
|
+
PORTAL_OAI = PORTAL_BASE + "/oai/"
|
|
51
|
+
TDA_BASE = "https://tsl.access.preservica.com"
|
|
52
|
+
GLO_LAND = "https://s3.glo.texas.gov/lookup/index.php"
|
|
53
|
+
TSLAC_HOME = "https://www.tsl.texas.gov/"
|
|
54
|
+
TSLAC_RANGERS = "https://www.tsl.texas.gov/agency/items/texas-rangers"
|
|
55
|
+
UA = (
|
|
56
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
|
57
|
+
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
58
|
+
)
|
|
59
|
+
TIMEOUT = 60.0
|
|
60
|
+
OAI_NS = {"oai": "http://www.openarchives.org/OAI/2.0/", "dc": "http://purl.org/dc/elements/1.1/"}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _client() -> httpx.Client:
|
|
64
|
+
return httpx.Client(headers={"User-Agent": UA}, timeout=TIMEOUT, follow_redirects=True)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _clean(text: str) -> str:
|
|
68
|
+
text = re.sub(r"<[^>]+>", " ", text)
|
|
69
|
+
return htmlmod.unescape(re.sub(r"\s+", " ", text)).strip()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _ark_id(raw: str) -> str:
|
|
73
|
+
raw = raw.strip()
|
|
74
|
+
if raw.startswith("ark:/"):
|
|
75
|
+
m = re.search(r"metap?th\d+|metadc\d+", raw)
|
|
76
|
+
if m:
|
|
77
|
+
return m.group(0)
|
|
78
|
+
parts = raw.rstrip("/").split("/")
|
|
79
|
+
return parts[-1] if parts else raw
|
|
80
|
+
return raw
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _normalize_ark(ark_token: str) -> str:
|
|
84
|
+
token = _ark_id(ark_token)
|
|
85
|
+
return f"ark:/67531/{token}"
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _parse_item_date(value: str | None) -> tuple[date | None, date | None]:
|
|
89
|
+
if not value:
|
|
90
|
+
return None, None
|
|
91
|
+
value = value.strip()
|
|
92
|
+
m = re.match(r"^(\d{4})-(\d{2})-(\d{2})", value)
|
|
93
|
+
if m:
|
|
94
|
+
d = date(int(m.group(1)), int(m.group(2)), int(m.group(3)))
|
|
95
|
+
return d, d
|
|
96
|
+
m = re.match(r"^(\d{4})/(\d{4})$", value)
|
|
97
|
+
if m:
|
|
98
|
+
return date(int(m.group(1)), 1, 1), date(int(m.group(2)), 12, 31)
|
|
99
|
+
m = re.match(r"^(\d{4})$", value)
|
|
100
|
+
if m:
|
|
101
|
+
y = int(m.group(1))
|
|
102
|
+
return date(y, 1, 1), date(y, 12, 31)
|
|
103
|
+
return None, None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _entry_matches_filters(
|
|
107
|
+
entry: dict,
|
|
108
|
+
county: str | None,
|
|
109
|
+
type_filter: str | None,
|
|
110
|
+
date_from: date | None,
|
|
111
|
+
date_to: date | None,
|
|
112
|
+
) -> bool:
|
|
113
|
+
if type_filter:
|
|
114
|
+
if (entry.get("type") or "").lower() != type_filter.lower():
|
|
115
|
+
return False
|
|
116
|
+
if county:
|
|
117
|
+
blob = " ".join(
|
|
118
|
+
filter(
|
|
119
|
+
None,
|
|
120
|
+
[
|
|
121
|
+
entry.get("title"),
|
|
122
|
+
entry.get("description"),
|
|
123
|
+
" ".join(entry.get("subjects") or []),
|
|
124
|
+
],
|
|
125
|
+
)
|
|
126
|
+
).lower()
|
|
127
|
+
if county.lower() not in blob:
|
|
128
|
+
return False
|
|
129
|
+
if date_from or date_to:
|
|
130
|
+
start, end = _parse_item_date(entry.get("date"))
|
|
131
|
+
if start is None and end is None:
|
|
132
|
+
return False
|
|
133
|
+
lo = start or end
|
|
134
|
+
hi = end or start
|
|
135
|
+
assert lo is not None and hi is not None
|
|
136
|
+
if date_from and hi < date_from:
|
|
137
|
+
return False
|
|
138
|
+
if date_to and lo > date_to:
|
|
139
|
+
return False
|
|
140
|
+
return True
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _opensearch_entry(raw: dict) -> dict:
|
|
144
|
+
return {
|
|
145
|
+
"ark": raw.get("id", ""),
|
|
146
|
+
"title": raw.get("title", ""),
|
|
147
|
+
"creator": raw.get("dc:creator", ""),
|
|
148
|
+
"date": raw.get("dc:date", ""),
|
|
149
|
+
"description": raw.get("dc:description", ""),
|
|
150
|
+
"type": raw.get("dc:type", ""),
|
|
151
|
+
"url": raw.get("link", ""),
|
|
152
|
+
"thumbnail": raw.get("thumbnail") or "",
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _fetch_opensearch_page(client: httpx.Client, query: str, page: int) -> dict:
|
|
157
|
+
params = {"q": query, "format": "json", "pw": str(page)}
|
|
158
|
+
resp = client.get(PORTAL_OPENSEARCH, params=params)
|
|
159
|
+
if resp.status_code != 200:
|
|
160
|
+
raise click.ClickException(f"OpenSearch returned HTTP {resp.status_code}")
|
|
161
|
+
data = resp.json()
|
|
162
|
+
feed = data.get("feed") or {}
|
|
163
|
+
total_s = feed.get("opensearch:totalResults", "0")
|
|
164
|
+
try:
|
|
165
|
+
total = int(total_s)
|
|
166
|
+
except ValueError:
|
|
167
|
+
total = 0
|
|
168
|
+
entries = [_opensearch_entry(e) for e in feed.get("entry") or []]
|
|
169
|
+
return {"total": total, "page": page, "entries": entries}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _build_portal_query(query: str, county: str | None) -> str:
|
|
173
|
+
parts = [query.strip()]
|
|
174
|
+
if county:
|
|
175
|
+
parts.append(county.strip())
|
|
176
|
+
return " ".join(p for p in parts if p)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _parse_oai_record(xml_text: str) -> dict:
|
|
180
|
+
root = ET.fromstring(xml_text)
|
|
181
|
+
err = root.find("oai:error", OAI_NS)
|
|
182
|
+
if err is not None:
|
|
183
|
+
code = err.get("code", "error")
|
|
184
|
+
raise click.ClickException(f"OAI error {code}: {(err.text or '').strip()}")
|
|
185
|
+
rec = root.find(".//oai:record", OAI_NS)
|
|
186
|
+
if rec is None:
|
|
187
|
+
raise click.ClickException("OAI response had no record")
|
|
188
|
+
header = rec.find("oai:header", OAI_NS)
|
|
189
|
+
identifier = ""
|
|
190
|
+
sets: list[str] = []
|
|
191
|
+
if header is not None:
|
|
192
|
+
id_el = header.find("oai:identifier", OAI_NS)
|
|
193
|
+
if id_el is not None and id_el.text:
|
|
194
|
+
identifier = id_el.text.strip()
|
|
195
|
+
for s in header.findall("oai:setSpec", OAI_NS):
|
|
196
|
+
if s.text:
|
|
197
|
+
sets.append(s.text.strip())
|
|
198
|
+
meta = rec.find(".//dc:title", OAI_NS)
|
|
199
|
+
titles = [el.text.strip() for el in rec.findall(".//dc:title", OAI_NS) if el.text]
|
|
200
|
+
creators = [el.text.strip() for el in rec.findall(".//dc:creator", OAI_NS) if el.text]
|
|
201
|
+
subjects = [el.text.strip() for el in rec.findall(".//dc:subject", OAI_NS) if el.text]
|
|
202
|
+
dates = [el.text.strip() for el in rec.findall(".//dc:date", OAI_NS) if el.text]
|
|
203
|
+
types = [el.text.strip() for el in rec.findall(".//dc:type", OAI_NS) if el.text]
|
|
204
|
+
desc = [el.text.strip() for el in rec.findall(".//dc:description", OAI_NS) if el.text]
|
|
205
|
+
ark = ""
|
|
206
|
+
m = re.search(r"metap?th\d+|metadc\d+", identifier)
|
|
207
|
+
if m:
|
|
208
|
+
ark = f"ark:/67531/{m.group(0)}"
|
|
209
|
+
return {
|
|
210
|
+
"oai_identifier": identifier,
|
|
211
|
+
"ark": ark,
|
|
212
|
+
"titles": titles,
|
|
213
|
+
"creators": creators,
|
|
214
|
+
"subjects": subjects,
|
|
215
|
+
"dates": dates,
|
|
216
|
+
"types": types,
|
|
217
|
+
"descriptions": desc,
|
|
218
|
+
"set_specs": sets,
|
|
219
|
+
"url": (PORTAL_BASE + "/" + ark + "/") if ark else "",
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _fetch_portal_item(client: httpx.Client, ark_token: str) -> dict:
|
|
224
|
+
ark = _normalize_ark(ark_token)
|
|
225
|
+
params = {"verb": "GetRecord", "identifier": ark, "metadataPrefix": "oai_dc"}
|
|
226
|
+
resp = client.get(PORTAL_OAI, params=params)
|
|
227
|
+
if resp.status_code != 200:
|
|
228
|
+
raise click.ClickException(f"OAI GetRecord returned HTTP {resp.status_code}")
|
|
229
|
+
data = _parse_oai_record(resp.text)
|
|
230
|
+
data["ark"] = ark
|
|
231
|
+
data["url"] = PORTAL_BASE + "/" + ark + "/"
|
|
232
|
+
data["browser_note"] = (
|
|
233
|
+
"Item pages and scans need a browser (ALTCHA challenge on texashistory.unt.edu)."
|
|
234
|
+
)
|
|
235
|
+
return data
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _curl_text(url: str) -> str:
|
|
239
|
+
"""Fetch a URL with curl when Python TLS is blocked (TSLAC Preservica host)."""
|
|
240
|
+
try:
|
|
241
|
+
proc = subprocess.run(
|
|
242
|
+
["curl", "-sS", "-L", "-A", UA, url],
|
|
243
|
+
capture_output=True,
|
|
244
|
+
text=True,
|
|
245
|
+
timeout=int(TIMEOUT),
|
|
246
|
+
check=False,
|
|
247
|
+
)
|
|
248
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
249
|
+
raise click.ClickException(f"curl failed: {exc}") from exc
|
|
250
|
+
if proc.returncode != 0:
|
|
251
|
+
err = (proc.stderr or "").strip() or f"exit {proc.returncode}"
|
|
252
|
+
raise click.ClickException(f"curl error: {err}")
|
|
253
|
+
if "403 Forbidden" in proc.stdout[:500] and "<rss" not in proc.stdout:
|
|
254
|
+
raise click.ClickException("TDA RSS returned a 403 page to curl")
|
|
255
|
+
return proc.stdout
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _fetch_tda_rss(query: str, limit: int) -> list[dict[str, str]]:
|
|
259
|
+
url = f"{TDA_BASE}/search/{quote(query)}/feed/rss2/"
|
|
260
|
+
feed = _curl_text(url)
|
|
261
|
+
results: list[dict[str, str]] = []
|
|
262
|
+
seen: set[str] = set()
|
|
263
|
+
for block in re.findall(r"<item>(.*?)</item>", feed, re.S):
|
|
264
|
+
title_m = re.search(r"<title>(.*?)</title>", block, re.S)
|
|
265
|
+
link_m = re.search(r"<link>(.*?)</link>", block, re.S)
|
|
266
|
+
if not title_m or not link_m:
|
|
267
|
+
continue
|
|
268
|
+
link = link_m.group(1).strip()
|
|
269
|
+
if link in seen:
|
|
270
|
+
continue
|
|
271
|
+
seen.add(link)
|
|
272
|
+
title = _clean(title_m.group(1))
|
|
273
|
+
if title.lower().startswith("search results for"):
|
|
274
|
+
continue
|
|
275
|
+
if title:
|
|
276
|
+
results.append({"title": title, "url": link})
|
|
277
|
+
if len(results) >= limit:
|
|
278
|
+
break
|
|
279
|
+
return results
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _print_portal_hit(rec: dict) -> None:
|
|
283
|
+
click.echo(rec.get("title") or "(no title)")
|
|
284
|
+
line = f" {rec.get('date') or ''} [{rec.get('type') or ''}] {rec.get('creator') or ''}".rstrip()
|
|
285
|
+
click.echo(line)
|
|
286
|
+
click.echo(f" {rec.get('ark')} {rec.get('url')}")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
|
|
290
|
+
def cli() -> None:
|
|
291
|
+
"""Search Texas archives: Portal to Texas History, Texas Digital Archive, URL builders."""
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@cli.group("portal")
|
|
295
|
+
def portal() -> None:
|
|
296
|
+
"""The Portal to Texas History (University of North Texas)."""
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
@portal.command("search")
|
|
300
|
+
@click.argument("query", nargs=-1, required=True)
|
|
301
|
+
@click.option("--county", default=None, help="Add a county term to the query and filter hits that mention it.")
|
|
302
|
+
@click.option("--date-from", default=None, help="Keep hits on or after this date (YYYY-MM-DD).")
|
|
303
|
+
@click.option("--date-to", default=None, help="Keep hits on or before this date (YYYY-MM-DD).")
|
|
304
|
+
@click.option("--type", "type_filter", default=None, help="Keep hits whose dc:type matches, e.g. text_newspaper.")
|
|
305
|
+
@click.option("--limit", default=10, show_default=True, type=int, help="Maximum hits to print after filters.")
|
|
306
|
+
@click.option("--pages", default=3, show_default=True, type=int, help="OpenSearch pages to scan (100 hits each).")
|
|
307
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
308
|
+
def cmd_portal_search(
|
|
309
|
+
query: tuple[str, ...],
|
|
310
|
+
county: str | None,
|
|
311
|
+
date_from: str | None,
|
|
312
|
+
date_to: str | None,
|
|
313
|
+
type_filter: str | None,
|
|
314
|
+
limit: int,
|
|
315
|
+
pages: int,
|
|
316
|
+
as_json: bool,
|
|
317
|
+
) -> None:
|
|
318
|
+
"""Search the Portal via its public OpenSearch JSON API."""
|
|
319
|
+
d_from = date.fromisoformat(date_from) if date_from else None
|
|
320
|
+
d_to = date.fromisoformat(date_to) if date_to else None
|
|
321
|
+
q = _build_portal_query(" ".join(query), county)
|
|
322
|
+
matched: list[dict] = []
|
|
323
|
+
total_reported = 0
|
|
324
|
+
with _client() as client:
|
|
325
|
+
for page in range(1, pages + 1):
|
|
326
|
+
if len(matched) >= limit:
|
|
327
|
+
break
|
|
328
|
+
batch = _fetch_opensearch_page(client, q, page)
|
|
329
|
+
total_reported = batch["total"]
|
|
330
|
+
if not batch["entries"] and page > 1:
|
|
331
|
+
break
|
|
332
|
+
for entry in batch["entries"]:
|
|
333
|
+
full = dict(entry)
|
|
334
|
+
full["subjects"] = []
|
|
335
|
+
if _entry_matches_filters(full, county, type_filter, d_from, d_to):
|
|
336
|
+
matched.append(entry)
|
|
337
|
+
if len(matched) >= limit:
|
|
338
|
+
break
|
|
339
|
+
payload = {
|
|
340
|
+
"query": q,
|
|
341
|
+
"opensearch_total": total_reported,
|
|
342
|
+
"returned": len(matched),
|
|
343
|
+
"records": matched,
|
|
344
|
+
"search_url": PORTAL_BASE + "/search/?" + urlencode({"q": q, "t": "fulltext"}),
|
|
345
|
+
"note": "HTML search requires a browser (ALTCHA). Filters apply to OpenSearch fields only.",
|
|
346
|
+
}
|
|
347
|
+
if as_json:
|
|
348
|
+
click.echo(json.dumps(payload, indent=1))
|
|
349
|
+
return
|
|
350
|
+
click.echo(f"{total_reported} OpenSearch hit(s) for {q!r}; showing {len(matched)} after filters:")
|
|
351
|
+
click.echo(payload["search_url"] + " (browser)")
|
|
352
|
+
for rec in matched:
|
|
353
|
+
_print_portal_hit(rec)
|
|
354
|
+
click.echo()
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
@portal.command("item")
|
|
358
|
+
@click.argument("ark_id")
|
|
359
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
360
|
+
def cmd_portal_item(ark_id: str, as_json: bool) -> None:
|
|
361
|
+
"""Fetch Dublin Core metadata for one Portal item (OAI-PMH GetRecord)."""
|
|
362
|
+
with _client() as client:
|
|
363
|
+
data = _fetch_portal_item(client, ark_id)
|
|
364
|
+
if as_json:
|
|
365
|
+
click.echo(json.dumps(data, indent=1))
|
|
366
|
+
return
|
|
367
|
+
title = (data.get("titles") or ["(no title)"])[0]
|
|
368
|
+
click.echo(title)
|
|
369
|
+
click.echo(f" {data['ark']}")
|
|
370
|
+
if data.get("creators"):
|
|
371
|
+
click.echo(" Creator(s): " + "; ".join(data["creators"][:6]))
|
|
372
|
+
if data.get("dates"):
|
|
373
|
+
click.echo(" Date(s): " + "; ".join(data["dates"][:6]))
|
|
374
|
+
if data.get("types"):
|
|
375
|
+
click.echo(" Type(s): " + ", ".join(data["types"]))
|
|
376
|
+
if data.get("subjects"):
|
|
377
|
+
click.echo(" Subject(s): " + "; ".join(data["subjects"][:8]))
|
|
378
|
+
click.echo(f" {data['url']}")
|
|
379
|
+
click.echo(f" {data['browser_note']}")
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
@cli.command("tda")
|
|
383
|
+
@click.argument("query")
|
|
384
|
+
@click.option("--limit", default=10, show_default=True, type=int)
|
|
385
|
+
@click.option("--json", "as_json", is_flag=True, help="Output compact structured JSON.")
|
|
386
|
+
def cmd_tda(query: str, limit: int, as_json: bool) -> None:
|
|
387
|
+
"""Search the Texas Digital Archive (TSLAC Preservica RSS feed)."""
|
|
388
|
+
results = _fetch_tda_rss(query, limit)
|
|
389
|
+
payload = {
|
|
390
|
+
"search_url": f"{TDA_BASE}/?s={quote(query)}",
|
|
391
|
+
"feed_url": f"{TDA_BASE}/search/{quote(query)}/feed/rss2/",
|
|
392
|
+
"returned": len(results),
|
|
393
|
+
"results": results,
|
|
394
|
+
}
|
|
395
|
+
if as_json:
|
|
396
|
+
click.echo(json.dumps(payload, indent=1))
|
|
397
|
+
return
|
|
398
|
+
click.echo(f"TDA search: {payload['search_url']}")
|
|
399
|
+
if not results:
|
|
400
|
+
click.echo("No results in the RSS feed (feed returns at most ~25 items per query).")
|
|
401
|
+
return
|
|
402
|
+
for r in results:
|
|
403
|
+
click.echo(f"- {r['title']}")
|
|
404
|
+
click.echo(f" {r['url']}")
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
@cli.command("url")
|
|
408
|
+
@click.argument("query", required=False, default="")
|
|
409
|
+
@click.option("--portal", is_flag=True, help="Portal to Texas History full-text search URL.")
|
|
410
|
+
@click.option("--tda", is_flag=True, help="Texas Digital Archive search URL.")
|
|
411
|
+
@click.option("--glo", is_flag=True, help="Texas GLO land grant lookup (browser-only).")
|
|
412
|
+
@click.option("--rangers", is_flag=True, help="TSLAC Texas Rangers collection pointer.")
|
|
413
|
+
@click.option("--tslac", is_flag=True, help="Texas State Library and Archives Commission home.")
|
|
414
|
+
def cmd_url(query: str, portal: bool, tda: bool, glo: bool, rangers: bool, tslac: bool) -> None:
|
|
415
|
+
"""Print verified portal URLs (no search is run)."""
|
|
416
|
+
any_flag = portal or tda or glo or rangers or tslac
|
|
417
|
+
show_all = not any_flag
|
|
418
|
+
q = query or "Houston"
|
|
419
|
+
if portal or show_all:
|
|
420
|
+
click.echo("Portal to Texas History (browser; ALTCHA on HTML):")
|
|
421
|
+
click.echo(" " + PORTAL_BASE + "/search/?" + urlencode({"q": q, "t": "fulltext"}))
|
|
422
|
+
click.echo("Portal OpenSearch JSON (CLI uses this):")
|
|
423
|
+
click.echo(" " + PORTAL_OPENSEARCH + "?" + urlencode({"q": q, "format": "json"}))
|
|
424
|
+
if tda or show_all:
|
|
425
|
+
click.echo("Texas Digital Archive:")
|
|
426
|
+
click.echo(f" {TDA_BASE}/?s={quote(q)}")
|
|
427
|
+
if glo or show_all:
|
|
428
|
+
click.echo("Texas General Land Office Land Grant Search (browser-only; SPA):")
|
|
429
|
+
click.echo(f" {GLO_LAND}")
|
|
430
|
+
click.echo(" Texas was not a public-land state; state grants are indexed here, not BLM GLO patents.")
|
|
431
|
+
if rangers or show_all:
|
|
432
|
+
click.echo("TSLAC Texas Rangers:")
|
|
433
|
+
click.echo(f" {TSLAC_RANGERS}")
|
|
434
|
+
click.echo(" Ranger muster rolls: open records request or in-person at TSLAC.")
|
|
435
|
+
if tslac or show_all:
|
|
436
|
+
click.echo("Texas State Library and Archives Commission:")
|
|
437
|
+
click.echo(f" {TSLAC_HOME}")
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
if __name__ == "__main__":
|
|
441
|
+
cli()
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: uk-archives
|
|
3
|
+
description: Research historical and genealogical records in England and the UK via the bundled `uk-archives` CLI. Covers The National Archives Discovery free JSON API (wills, Chancery, local deposit catalogues) and FreeREG parish register transcriptions (Rails form over HTTP, no API key). Also documents browser-only paths for Nottinghamshire Archives CalmView, British History Online, and GENUKI, with honest notes on subscription sites (Ancestry UK, Findmypast, GRO PDF ordering). Use when tracing English ancestors before emigration, finding PCC wills, parish baptisms or marriages, or deciding whether a UK record is online, digitised, or visit-only.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# UK Archives: England and The National Archives
|
|
7
|
+
|
|
8
|
+
Portals: [The National Archives Discovery](https://discovery.nationalarchives.gov.uk/), [FreeREG](https://www.freereg.org.uk/), [Nottinghamshire Archives catalogue](https://nawcat.nottinghamshire.gov.uk/), [British History Online](https://www.british-history.ac.uk/), [GENUKI England](https://www.genuki.org.uk/big/eng).
|
|
9
|
+
|
|
10
|
+
## Bundled CLI (`scripts/uk-archives`)
|
|
11
|
+
|
|
12
|
+
Path: `skills/uk-archives/scripts/uk-archives`
|
|
13
|
+
|
|
14
|
+
A standalone executable Python CLI with a PEP 723 `#!/usr/bin/env -S uv run --script` shebang and inline dependencies (`click`, `httpx`). No virtualenv setup, no API key, no account.
|
|
15
|
+
|
|
16
|
+
### The National Archives Discovery
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Search Discovery catalogue hits filtered by county text
|
|
20
|
+
skills/uk-archives/scripts/uk-archives discovery search Lincoln --held-by Norfolk --limit 10
|
|
21
|
+
|
|
22
|
+
# PCC wills (PROB 11) for a surname and date range
|
|
23
|
+
skills/uk-archives/scripts/uk-archives discovery search Lincoln \
|
|
24
|
+
--date-from 1550 --date-to 1660 --collection "PROB 11" --limit 20 --json
|
|
25
|
+
|
|
26
|
+
# One record (verified detail endpoint uses /API/records/v1/details/<id>)
|
|
27
|
+
skills/uk-archives/scripts/uk-archives discovery detail <record-id> --json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Search options: `--held-by` (free text appended to the query), `--date-from` / `--date-to` (YYYY or YYYY-MM-DD, mapped to `sps.dateFrom` / `sps.dateTo`), `--collection` (appended to the query and used to post-filter by catalogue reference), `--limit` (the API returns at most 15 rows per request; the CLI slices to your limit). Each hit prints id, reference, dates, title, places, and a Discovery web URL.
|
|
31
|
+
|
|
32
|
+
The detail route verified live is `https://discovery.nationalarchives.gov.uk/API/records/v1/details/<id>` (not `.../search/v1/records/v1/details/...`, which returns 404).
|
|
33
|
+
|
|
34
|
+
### FreeREG parish registers
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Search FreeREG by surname, county Chapman code, and year range
|
|
38
|
+
skills/uk-archives/scripts/uk-archives freereg search --surname Lincoln --county NFK \
|
|
39
|
+
--from-year 1550 --to-year 1650
|
|
40
|
+
|
|
41
|
+
# Filter hits by parish or register text
|
|
42
|
+
skills/uk-archives/scripts/uk-archives freereg search --surname Lincoln --county NFK \
|
|
43
|
+
--from-year 1550 --to-year 1650 --place-contains Hingham
|
|
44
|
+
|
|
45
|
+
# Search Nottinghamshire (NTT) parish registers, JSON output
|
|
46
|
+
skills/uk-archives/scripts/uk-archives freereg search --surname Smith --county NTT \
|
|
47
|
+
--from-year 1570 --to-year 1630 --json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
FreeREG has no public JSON API. The CLI GETs the home page for a Rails `authenticity_token`, POSTs to `/search_queries`, and parses the results table HTML. No CAPTCHA appeared in live tests on 2026-11-24. Chapman codes (for example `NTT` for Nottinghamshire, `LND` for London, `KEN` for Kent, `NFK` for Norfolk) are passed directly to FreeREG.
|
|
51
|
+
|
|
52
|
+
Options: `--given`, `--county` (Chapman code or county name), `--from-year`, `--to-year`, `--record-type` (`all` / `baptism` / `marriage` / `burial`), `--place-contains`, `--json`.
|
|
53
|
+
|
|
54
|
+
### URL builders (no search run)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
skills/uk-archives/scripts/uk-archives url --discovery "Lincoln Norfolk"
|
|
58
|
+
skills/uk-archives/scripts/uk-archives url --freereg
|
|
59
|
+
skills/uk-archives/scripts/uk-archives url --notts Lincoln
|
|
60
|
+
skills/uk-archives/scripts/uk-archives url --bho "Nottinghamshire"
|
|
61
|
+
skills/uk-archives/scripts/uk-archives url --genuki nottinghamshire
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What is searchable online
|
|
65
|
+
|
|
66
|
+
- **Discovery:** Key-free JSON search and detail for the national catalogue (PCC wills `PROB 11`, Chancery, records held at TNA and other repositories). Digitised will images are linked from the Discovery record page when `digitised: true`.
|
|
67
|
+
- **FreeREG:** Volunteer transcriptions of Church of England registers (and related collections). Strong for English counties when parish registers are not on FamilySearch.
|
|
68
|
+
- **British History Online:** Open scholarly texts and Victoria County History material. Plain HTTP returned 302 to the site home on 2026-11-24. Use `url --bho` and search in the browser (no stable API verified).
|
|
69
|
+
- **GENUKI:** Parish and county guidance pages. Use `url --genuki` for England or county hubs (`england`, `kent`, `london`, `nottingham`, `nottinghamshire`, `yorkshire`).
|
|
70
|
+
|
|
71
|
+
## What is browser-only or subscription-only
|
|
72
|
+
|
|
73
|
+
- **County Archives CalmView catalogues** (such as Nottinghamshire Archives `nawcat.nottinghamshire.gov.uk`): HTTPS timed out after 45s in automated checks on 2026-11-24. Use `url --notts` and search in a browser.
|
|
74
|
+
- **Ancestry UK / Findmypast / GRO certificate PDF ordering:** Subscription or pay-per-item. Not implemented; no API verified.
|
|
75
|
+
- **Discovery advanced held-by filter parameters** (`sps.heldByReference`, `sps.departmentReference`, and similar) did not narrow results in live tests. Use `--held-by` as query text (for example `Nottinghamshire` or `Norfolk`) instead.
|
|
76
|
+
|
|
77
|
+
## Research workflow
|
|
78
|
+
|
|
79
|
+
Priority order for English pre-emigration and parish research:
|
|
80
|
+
|
|
81
|
+
1. **FreeREG** for parish baptisms, marriages, and burials by surname, Chapman county code, and year window.
|
|
82
|
+
2. **Discovery** for PCC wills (`PROB 11`) and Chancery records when parish registers do not establish family links.
|
|
83
|
+
3. **County archive manuscript catalogues** in the browser when Discovery points to local deposit references.
|
|
84
|
+
4. **BHO / GENUKI** for parish history, boundary changes, and manorial context.
|
|
85
|
+
5. Cross-check transcribed parish entries against original register images or Bishop's Transcripts on FamilySearch, Ancestry UK, or Findmypast before recording them as proved in `data/`.
|
|
86
|
+
|
|
87
|
+
## Verification log (verified live 2026-11-24)
|
|
88
|
+
|
|
89
|
+
- Discovery search GET `https://discovery.nationalarchives.gov.uk/API/search/v1/records?sps.searchQuery=...&rows=15`: HTTP 200 JSON with `count` and `records[]`.
|
|
90
|
+
- Discovery date filtering (`sps.dateFrom`, `sps.dateTo`) and `PROB 11` post-filtering: HTTP 200 JSON with valid catalogue references.
|
|
91
|
+
- Discovery detail GET `https://discovery.nationalarchives.gov.uk/API/records/v1/details/<id>`: HTTP 200 JSON with `digitised` and `citableReference`. Path `.../API/search/v1/records/v1/details/<id>` returned **404** (do not use).
|
|
92
|
+
- FreeREG GET `https://www.freereg.org.uk/`: HTTP **200**, CSRF token present; POST `/search_queries` returned HTTP **200** with parseable HTML table rows.
|
|
93
|
+
- British History Online GET `https://www.british-history.ac.uk/`: HTTP **302** (site up; no search API wired).
|
|
94
|
+
- Nottinghamshire CalmView GET `https://nawcat.nottinghamshire.gov.uk/CalmView/`: connection timeout at 45s (browser-only note; no machine search).
|
|
95
|
+
- CLI: `uv run --script skills/uk-archives/scripts/uk-archives --help`, `discovery search`, `discovery detail`, `freereg search`, and `url` all exited **0** on 2026-11-24.
|
|
96
|
+
|
|
97
|
+
## What this skill does not cover
|
|
98
|
+
|
|
99
|
+
- Scotland, Wales, and Ireland beyond what Discovery holds for the whole UK catalogue.
|
|
100
|
+
- Subscription sites (Ancestry UK, Findmypast, MyHeritage) and the GRO index ordering flow.
|
|
101
|
+
- Do not invent Discovery detail URLs under `/API/search/v1/.../details/` or a FreeREG JSON API. Where no machine interface was verified, the skill says so and gives a URL builder or browser path instead.
|