@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.
Files changed (102) hide show
  1. package/dist/assets/cached-ocr.py +556 -0
  2. package/dist/assets/ocr.md +52 -0
  3. package/dist/assets/prep-scan.md +59 -0
  4. package/dist/assets/prep-scan.py +891 -0
  5. package/dist/bundled-skills/acpl-persi/SKILL.md +94 -0
  6. package/dist/bundled-skills/acpl-persi/scripts/persi +268 -0
  7. package/dist/bundled-skills/archive-org/SKILL.md +129 -0
  8. package/dist/bundled-skills/archive-org/scripts/archive-org +879 -0
  9. package/dist/bundled-skills/blm-glo/SKILL.md +54 -0
  10. package/dist/bundled-skills/california-archives/SKILL.md +120 -0
  11. package/dist/bundled-skills/california-archives/scripts/ca-archives +373 -0
  12. package/dist/bundled-skills/chronicling-america/SKILL.md +100 -0
  13. package/dist/bundled-skills/chronicling-america/scripts/chronam +250 -0
  14. package/dist/bundled-skills/cyndis-list/SKILL.md +53 -0
  15. package/dist/bundled-skills/findagrave/SKILL.md +116 -0
  16. package/dist/bundled-skills/findagrave/scripts/findagrave +520 -0
  17. package/dist/bundled-skills/hathitrust/SKILL.md +110 -0
  18. package/dist/bundled-skills/hathitrust/scripts/hathi +194 -0
  19. package/dist/bundled-skills/kentucky-archives/SKILL.md +123 -0
  20. package/dist/bundled-skills/kentucky-archives/scripts/ky-archives +358 -0
  21. package/dist/bundled-skills/library-of-michigan/SKILL.md +111 -0
  22. package/dist/bundled-skills/library-of-michigan/scripts/michiganology +346 -0
  23. package/dist/bundled-skills/missouri-archives/SKILL.md +100 -0
  24. package/dist/bundled-skills/missouri-archives/scripts/mo-archives +528 -0
  25. package/dist/bundled-skills/nara-catalog-search/SKILL.md +118 -0
  26. package/dist/bundled-skills/nara-catalog-search/scripts/nara +934 -0
  27. package/dist/bundled-skills/narrative-audio/SKILL.md +103 -0
  28. package/dist/bundled-skills/narrative-audio/references/script-rules.md +109 -0
  29. package/dist/bundled-skills/narrative-audio/scripts/narrative-audio +290 -0
  30. package/dist/bundled-skills/new-jersey-archives/SKILL.md +118 -0
  31. package/dist/bundled-skills/new-jersey-archives/scripts/nj-archives +585 -0
  32. package/dist/bundled-skills/openarchieven/SKILL.md +90 -0
  33. package/dist/bundled-skills/openarchieven/scripts/openarchieven +432 -0
  34. package/dist/bundled-skills/texas-archives/SKILL.md +93 -0
  35. package/dist/bundled-skills/texas-archives/scripts/texas-archives +441 -0
  36. package/dist/bundled-skills/uk-archives/SKILL.md +101 -0
  37. package/dist/bundled-skills/uk-archives/scripts/uk-archives +391 -0
  38. package/dist/bundled-skills/usgs-gnis/SKILL.md +89 -0
  39. package/dist/bundled-skills/usgs-gnis/scripts/gnis +254 -0
  40. package/dist/bundled-skills/virginia-archives/SKILL.md +104 -0
  41. package/dist/bundled-skills/virginia-archives/scripts/va-archives +466 -0
  42. package/dist/bundled-skills/wikitree/SKILL.md +148 -0
  43. package/dist/bundled-skills/wikitree/scripts/wikitree +219 -0
  44. package/dist/cli.d.ts +1 -1
  45. package/dist/cli.d.ts.map +1 -1
  46. package/dist/cli.js +383 -26
  47. package/dist/cli.js.map +1 -1
  48. package/dist/client.js +1 -1
  49. package/dist/commands/init.js +3 -3
  50. package/dist/commands/ops/audit.d.ts +138 -0
  51. package/dist/commands/ops/audit.d.ts.map +1 -0
  52. package/dist/commands/ops/audit.js +867 -0
  53. package/dist/commands/ops/audit.js.map +1 -0
  54. package/dist/commands/ops/context.d.ts +100 -0
  55. package/dist/commands/ops/context.d.ts.map +1 -0
  56. package/dist/commands/ops/context.js +917 -0
  57. package/dist/commands/ops/context.js.map +1 -0
  58. package/dist/commands/ops/help.d.ts +6 -0
  59. package/dist/commands/ops/help.d.ts.map +1 -0
  60. package/dist/commands/ops/help.js +74 -0
  61. package/dist/commands/ops/help.js.map +1 -0
  62. package/dist/commands/ops/index.d.ts +6 -0
  63. package/dist/commands/ops/index.d.ts.map +1 -0
  64. package/dist/commands/ops/index.js +6 -0
  65. package/dist/commands/ops/index.js.map +1 -0
  66. package/dist/commands/ops/integrate.d.ts +56 -0
  67. package/dist/commands/ops/integrate.d.ts.map +1 -0
  68. package/dist/commands/ops/integrate.js +872 -0
  69. package/dist/commands/ops/integrate.js.map +1 -0
  70. package/dist/commands/ops/sync.d.ts +177 -0
  71. package/dist/commands/ops/sync.d.ts.map +1 -0
  72. package/dist/commands/ops/sync.js +1078 -0
  73. package/dist/commands/ops/sync.js.map +1 -0
  74. package/dist/commands/ops/telemetry.d.ts +79 -0
  75. package/dist/commands/ops/telemetry.d.ts.map +1 -0
  76. package/dist/commands/ops/telemetry.js +249 -0
  77. package/dist/commands/ops/telemetry.js.map +1 -0
  78. package/dist/commands/records/help.d.ts +18 -0
  79. package/dist/commands/records/help.d.ts.map +1 -0
  80. package/dist/commands/records/help.js +174 -0
  81. package/dist/commands/records/help.js.map +1 -0
  82. package/dist/commands/records/index.d.ts +5 -0
  83. package/dist/commands/records/index.d.ts.map +1 -0
  84. package/dist/commands/records/index.js +5 -0
  85. package/dist/commands/records/index.js.map +1 -0
  86. package/dist/commands/records/registry.d.ts +32 -0
  87. package/dist/commands/records/registry.d.ts.map +1 -0
  88. package/dist/commands/records/registry.js +227 -0
  89. package/dist/commands/records/registry.js.map +1 -0
  90. package/dist/commands/records/resolve.d.ts +14 -0
  91. package/dist/commands/records/resolve.d.ts.map +1 -0
  92. package/dist/commands/records/resolve.js +61 -0
  93. package/dist/commands/records/resolve.js.map +1 -0
  94. package/dist/commands/records/runner.d.ts +25 -0
  95. package/dist/commands/records/runner.d.ts.map +1 -0
  96. package/dist/commands/records/runner.js +224 -0
  97. package/dist/commands/records/runner.js.map +1 -0
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +2 -0
  101. package/dist/index.js.map +1 -1
  102. package/package.json +3 -3
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: acpl-persi
3
+ description: Search the Allen County Public Library Genealogy Center's free PERSI (Periodical Source Index) via the bundled `persi` CLI or the website, to find articles in county historical society newsletters and other genealogy periodicals. Covers CLI usage, the three search modes (surname, article title, location), what PERSI is and is not, getting article copies, and planning an in-person visit to Fort Wayne, Indiana. Use when hunting periodical citations for a surname or place, or when a lead points to a society newsletter.
4
+ ---
5
+
6
+ # ACPL PERSI
7
+
8
+ This skill includes a standalone executable Python CLI at `skills/acpl-persi/scripts/persi` 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 PERSI is:** the Periodical Source Index, produced by the staff of The Genealogy Center of the Allen County Public Library (ACPL), Fort Wayne, Indiana. It is the largest subject index to genealogy and local history periodicals, with more than 3.2 million citations to articles in 11,000+ periodical titles from local, state, national, and international societies.
11
+ - **What it is not:** a full-text archive. A hit is a citation: article title, periodical, year, publisher. PERSI indexes article titles, not article contents, so search for topics and surnames around an ancestor's life, not for a person's full story. Full text comes from the holding library, the publisher, WorldCat, or the Genealogy Center's copy service.
12
+ - **Cost:** free to search. No account, sign-in, or subscription is needed. PERSI was previously on Ancestry and Findmypast behind paywalls; ACPL has hosted it free on its own site since 2022.
13
+
14
+ ## Bundled CLI (`scripts/persi`)
15
+
16
+ Path: `skills/acpl-persi/scripts/persi`
17
+
18
+ ### Search by surname
19
+
20
+ ```bash
21
+ # Lincoln articles, first 25 hits
22
+ skills/acpl-persi/scripts/persi surname Lincoln
23
+
24
+ # JSON output, 50 hits
25
+ skills/acpl-persi/scripts/persi surname Lincoln --limit 50 --json
26
+ ```
27
+
28
+ ### Search by article-title keyword
29
+
30
+ ```bash
31
+ skills/acpl-persi/scripts/persi title Lincoln --limit 25
32
+ skills/acpl-persi/scripts/persi title "Clara Barton"
33
+ ```
34
+
35
+ ### Search by location (category counts)
36
+
37
+ ```bash
38
+ # Illinois statewide: returns article counts per category, not articles
39
+ skills/acpl-persi/scripts/persi location --state IL
40
+
41
+ # A single county (county name as PERSI lists it; blank means statewide)
42
+ skills/acpl-persi/scripts/persi location --state IL --county Sangamon
43
+ ```
44
+
45
+ The location search returns counts per category (for example History, Cemeteries, Military Records, Census Records, Court Records, Deeds, Directories, Land Records, Maps). Pick a category on the website to drill into its articles; the CLI does not drill down because the drill-down links are session pages, not a stable pattern.
46
+
47
+ ### Website search page for a mode
48
+
49
+ ```bash
50
+ skills/acpl-persi/scripts/persi url surname
51
+ ```
52
+
53
+ PERSI result pages are POST forms, so there is no shareable result URL. This prints the search form URL instead.
54
+
55
+ ## Website search and form rules (verified live 2026-11-24)
56
+
57
+ - Home: `https://www.genealogycenter.info/persi/`
58
+ - Surname form: `https://www.genealogycenter.info/search_persisurname.php`, POST to `results_persisurname.php` with fields `surname`, `sort=title`, `submit=Search`.
59
+ - Article-title form: `https://www.genealogycenter.info/search_persiarttitle.php`, POST to `results_persiarttitle.php` with fields `keyword`, `sort=title`, `submit=Search`.
60
+ - Location form: `https://www.genealogycenter.info/search_persilocation.php`, POST to `results_persilocation.php` with fields `subloc=USA`, `cosearch=USA`, `usloc=<two-letter state code>`, `county=<name or blank>`, `submit=Search`. The state dropdown uses two-letter codes (`IL`, `CA`, `MO`, `GEN` for US general); the county dropdown is populated by JavaScript after a state is picked, so on the website pick the state first, then the county.
61
+ - Results render as a DataTable with columns Article Title, Periodical, Year Published, Publisher. Some rows carry a free-online icon linking directly to a digitized, copyright-clear issue; ACPL adds these links gradually as it finds issues online.
62
+ - No wildcards are available. Quoted phrases work in the search boxes.
63
+ - There is no public PERSI API. Do not invent one; the POST forms above are the machine interface.
64
+
65
+ ## Getting the article after a hit
66
+
67
+ 1. Check the row for a free-online link first; if present, the issue is one click away.
68
+ 2. Search the periodical title on WorldCat to find a holding library near you.
69
+ 3. Contact the publishing society directly; many sell back issues cheaply.
70
+ 4. Order a copy from the Genealogy Center: the results page links to the article order form. The old form PDF at `acpl.lib.in.us/images/Documents/Gendocs/Forms/articlerequest.pdf` returned 404 on 2026-11-24, so use the link on the live results page and confirm the current fee there before quoting a price. Older guides cite $7.50 per order (up to 6 articles) plus $0.20 per page with a 6-8 week turnaround; treat that as stale until re-confirmed.
71
+ 5. In person, the Genealogy Center holds the periodicals indexed in PERSI, so a visit resolves the citation on the spot.
72
+
73
+ ## In-person visit
74
+
75
+ - **Genealogy Center, Allen County Public Library, 900 Library Plaza, Fort Wayne, IN 46801.** Phone 260-421-1225, email Genealogy@ACPL.Info.
76
+ - The Center holds more than 558,000 printed volumes and 795,800 microtext items, one of the largest physical genealogy collections in North America.
77
+ - Hours change; confirm on `https://genealogycenter.org` (redirects to the ACPL genealogy pages) before visiting.
78
+ - Beyond PERSI, the Center's free online databases total over 6 million records and images, including Allen County, Indiana resources (obituaries, cemeteries, marriages, deaths, courthouse records) and an African American gateway.
79
+
80
+ ## Research workflow
81
+
82
+ 1. `persi surname <Surname>` for the broad sweep; note periodical, year, and publisher for every plausible hit.
83
+ 2. `persi title <Keyword>` catches articles whose title mentions a surname, place, or historical event but whose surname indexing differs.
84
+ 3. `persi location --state <ST>` (then `--county <County>`) for place-first hunting; the Cemeteries, Court Records, and History categories are often the strongest leads.
85
+ 4. Repeat across each state along a family's migration path.
86
+ 5. Record each citation in `data/` with periodical, volume, issue, year, and ACPL call number when shown; mark whether a free-online link existed.
87
+
88
+ ## Environment variables
89
+
90
+ None. No key or account is needed.
91
+
92
+ ## Verified-live note
93
+
94
+ All endpoints and form fields above were verified live on 2026-11-24 by direct HTTP and by reading the live forms. Anything marked stale or reported (the old article-order fee) is labeled as such.
@@ -0,0 +1,268 @@
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
+ """Search the Allen County Public Library Genealogy Center's free PERSI
10
+ (Periodical Source Index) from the command line.
11
+
12
+ PERSI is a citation index, not a full-text archive: a hit gives the article
13
+ title, periodical, year, and publisher, plus a free link when the issue is
14
+ online and copyright-clear. Use the citation to find the article through a
15
+ library, WorldCat, or the Genealogy Center's article copy service.
16
+
17
+ All three search modes are plain POST forms on genealogycenter.info, verified
18
+ live 2026-11-24. No account, key, or sign-in is required.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import html as htmlmod
24
+ import json
25
+ import sys
26
+ import time
27
+ from html.parser import HTMLParser
28
+ from urllib.parse import urlencode
29
+
30
+ import click
31
+ import httpx
32
+
33
+ BASE = "https://www.genealogycenter.info"
34
+ SEARCH_PAGE = BASE + "/persi/"
35
+ SURNAME_URL = BASE + "/results_persisurname.php"
36
+ TITLE_URL = BASE + "/results_persiarttitle.php"
37
+ LOCATION_URL = BASE + "/results_persilocation.php"
38
+ USER_AGENT = "Mozilla/5.0"
39
+ # The Genealogy Center's front door intermittently 412/429s python-httpx's
40
+ # default header set. Plain curl-style headers (short UA, Accept */*) plus
41
+ # a Referer return 200 consistently; fetch() also retries once on 412/429.
42
+
43
+ US_STATES = {
44
+ "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
45
+ "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
46
+ "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
47
+ "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
48
+ "WV", "WI", "WY", "GEN",
49
+ }
50
+
51
+
52
+ class TableParser(HTMLParser):
53
+ """Collect rows of the first <table> whose cells look like PERSI results."""
54
+
55
+ def __init__(self) -> None:
56
+ super().__init__(convert_charrefs=True)
57
+ self.in_table = False
58
+ self.in_row = False
59
+ self.in_cell = False
60
+ self.current_row: list[str] = []
61
+ self.current_cell = ""
62
+ self.current_links: list[str] = []
63
+ self.cell_links: list[list[str]] = []
64
+ self.rows: list[dict] = []
65
+
66
+ def handle_starttag(self, tag, attrs):
67
+ attrs = dict(attrs)
68
+ if tag == "table":
69
+ self.in_table = True
70
+ if not self.in_table:
71
+ return
72
+ if tag == "tr":
73
+ self.in_row = True
74
+ self.current_row = []
75
+ self.cell_links = []
76
+ elif tag in ("td", "th") and self.in_row:
77
+ self.in_cell = True
78
+ self.current_cell = ""
79
+ self.current_links = []
80
+ elif tag == "a" and self.in_cell:
81
+ href = attrs.get("href", "")
82
+ if href:
83
+ self.current_links.append(href)
84
+
85
+ def handle_endtag(self, tag):
86
+ if tag == "table":
87
+ self.in_table = False
88
+ if not self.in_table and tag != "table":
89
+ return
90
+ if tag in ("td", "th") and self.in_cell:
91
+ self.in_cell = False
92
+ self.current_row.append(" ".join(self.current_cell.split()))
93
+ self.cell_links.append(list(self.current_links))
94
+ elif tag == "tr" and self.in_row:
95
+ self.in_row = False
96
+ if self.current_row:
97
+ self.rows.append(
98
+ {"cells": self.current_row, "links": self.cell_links}
99
+ )
100
+
101
+ def handle_data(self, data):
102
+ if self.in_cell:
103
+ self.current_cell += data
104
+
105
+
106
+ def fetch(url: str, data: dict, referer: str) -> str:
107
+ headers = {
108
+ "User-Agent": USER_AGENT,
109
+ "Accept": "*/*",
110
+ "Accept-Encoding": "identity",
111
+ "Referer": referer,
112
+ }
113
+ last_exc: Exception | None = None
114
+ for attempt in (1, 2):
115
+ try:
116
+ with httpx.Client(
117
+ headers=headers, timeout=60.0, follow_redirects=True
118
+ ) as client:
119
+ resp = client.post(url, data=data)
120
+ if resp.status_code in (412, 429) and attempt == 1:
121
+ time.sleep(5)
122
+ continue
123
+ resp.raise_for_status()
124
+ return resp.text
125
+ except httpx.HTTPError as exc:
126
+ last_exc = exc
127
+ raise click.ClickException(f"PERSI request failed: {last_exc}") from last_exc
128
+
129
+
130
+ def parse_articles(page: str) -> list[dict]:
131
+ parser = TableParser()
132
+ parser.feed(page)
133
+ articles = []
134
+ for row in parser.rows:
135
+ cells = row["cells"]
136
+ if len(cells) < 3:
137
+ continue
138
+ if cells[0].lower().startswith("article title"):
139
+ continue
140
+ free_links = [
141
+ link
142
+ for cell in row["links"]
143
+ for link in cell
144
+ if link.startswith("http")
145
+ ]
146
+ articles.append(
147
+ {
148
+ "title": cells[0],
149
+ "periodical": cells[1] if len(cells) > 1 else "",
150
+ "year": cells[2] if len(cells) > 2 else "",
151
+ "publisher": cells[3] if len(cells) > 3 else "",
152
+ "free_link": free_links[0] if free_links else None,
153
+ }
154
+ )
155
+ return articles
156
+
157
+
158
+ def parse_categories(page: str) -> list[dict]:
159
+ parser = TableParser()
160
+ parser.feed(page)
161
+ categories = []
162
+ for row in parser.rows:
163
+ cells = row["cells"]
164
+ if len(cells) == 2 and cells[1].replace(",", "").isdigit():
165
+ if cells[0].lower().startswith("category"):
166
+ continue
167
+ categories.append(
168
+ {"category": cells[0], "articles": int(cells[1].replace(",", ""))}
169
+ )
170
+ return categories
171
+
172
+
173
+ def emit(items: list[dict], as_json: bool, limit: int) -> None:
174
+ items = items[:limit]
175
+ if as_json:
176
+ click.echo(json.dumps(items, indent=2))
177
+ return
178
+ if not items:
179
+ click.echo("No results.")
180
+ return
181
+ for item in items:
182
+ if "articles" in item:
183
+ click.echo(f"{item['articles']:>6} {item['category']}")
184
+ else:
185
+ line = (
186
+ f"{item['title']} | {item['periodical']} | "
187
+ f"{item['year']} | {item['publisher']}"
188
+ )
189
+ click.echo(line)
190
+ if item.get("free_link"):
191
+ click.echo(f" free online: {item['free_link']}")
192
+ click.echo(f"({len(items)} shown)")
193
+
194
+
195
+ @click.group()
196
+ def cli() -> None:
197
+ """Search ACPL's free PERSI (Periodical Source Index)."""
198
+
199
+
200
+ @cli.command()
201
+ @click.argument("surname")
202
+ @click.option("--limit", default=25, show_default=True, help="Max results to show.")
203
+ @click.option("--json", "as_json", is_flag=True, help="Emit JSON.")
204
+ def surname(surname: str, limit: int, as_json: bool) -> None:
205
+ """Search PERSI by surname, e.g. persi surname Lincoln."""
206
+ page = fetch(SURNAME_URL, {"surname": surname, "sort": "title", "submit": "Search"}, BASE + "/search_persisurname.php")
207
+ emit(parse_articles(page), as_json, limit)
208
+
209
+
210
+ @cli.command()
211
+ @click.argument("keyword")
212
+ @click.option("--limit", default=25, show_default=True, help="Max results to show.")
213
+ @click.option("--json", "as_json", is_flag=True, help="Emit JSON.")
214
+ def title(keyword: str, limit: int, as_json: bool) -> None:
215
+ """Search PERSI by article-title keyword, e.g. persi title Lincoln."""
216
+ page = fetch(TITLE_URL, {"keyword": keyword, "sort": "title", "submit": "Search"}, BASE + "/search_persiarttitle.php")
217
+ emit(parse_articles(page), as_json, limit)
218
+
219
+
220
+ @cli.command()
221
+ @click.option("--state", required=True, help="Two-letter state code, e.g. MI. GEN for US general.")
222
+ @click.option("--county", default="", help="County name (optional; leave blank for statewide).")
223
+ @click.option("--json", "as_json", is_flag=True, help="Emit JSON.")
224
+ def location(state: str, county: str, as_json: bool) -> None:
225
+ """List PERSI article counts by category for a state/county.
226
+
227
+ Returns category counts, not articles: pick a category on the website
228
+ to drill into its articles.
229
+ """
230
+ state = state.upper()
231
+ if state not in US_STATES:
232
+ raise click.ClickException(f"Unknown state code: {state}")
233
+ page = fetch(
234
+ LOCATION_URL,
235
+ {
236
+ "subloc": "USA",
237
+ "cosearch": "USA",
238
+ "usloc": state,
239
+ "county": county,
240
+ "submit": "Search",
241
+ },
242
+ BASE + "/search_persilocation.php",
243
+ )
244
+ cats = parse_categories(page)
245
+ if not cats:
246
+ click.echo(
247
+ "No category counts returned. The county value may not match "
248
+ "PERSI's list; try a blank county (statewide) or check the "
249
+ "website form."
250
+ )
251
+ sys.exit(1)
252
+ emit(cats, as_json, len(cats))
253
+
254
+
255
+ @cli.command()
256
+ @click.argument("mode", type=click.Choice(["surname", "title", "location"]))
257
+ def url(mode: str) -> None:
258
+ """Print the PERSI website search page for a mode (POST forms have no shareable result URL)."""
259
+ pages = {
260
+ "surname": BASE + "/search_persisurname.php",
261
+ "title": BASE + "/search_persiarttitle.php",
262
+ "location": BASE + "/search_persilocation.php",
263
+ }
264
+ click.echo(pages[mode])
265
+
266
+
267
+ if __name__ == "__main__":
268
+ cli()
@@ -0,0 +1,129 @@
1
+ ---
2
+ name: archive-org
3
+ description: Search, inspect, grep cached OCR text, and download pages or files from Internet Archive items via the bundled Python 3.11+ `archive-org` CLI or the public advancedsearch and metadata APIs. Covers CLI usage, persistent local disk caching (`KINLOOM_IA_CACHE_DIR`), exact printed-page to leaf resolution, Lucene query syntax, field selection, pagination, file downloads, and worked examples. Use when finding digitized books, genealogies, newspapers, audio, or other archived material, or when searching inside or downloading scans from Internet Archive for family-history research.
4
+ ---
5
+
6
+ # Archive.org
7
+
8
+ This skill includes a standalone executable Python 3.11+ standard-library CLI at `skills/archive-org/scripts/archive-org` (`#!/usr/bin/env -S python3 -S`). No virtualenv, `uv`, third-party packages, or API key is required. The APIs are public and read-only.
9
+
10
+ ## Bundled CLI (`scripts/archive-org`)
11
+
12
+ Path: `skills/archive-org/scripts/archive-org`
13
+
14
+ ### Persistent local disk cache (`grep` & `page`)
15
+
16
+ `grep` and `page --printed-page` cache each item atomically at `~/.cache/kinloom-ia/<item_id>/` (overrideable via `KINLOOM_IA_CACHE_DIR`):
17
+
18
+ - `metadata.json`: item metadata and file inventory from `/metadata/<item_id>`.
19
+ - `scandata.xml`: raw IA leaf/page scan metadata (when present).
20
+ - `page_index.json`: pre-parsed bidirectional lookup table mapping `scandata` `leafNum`, BookReader `n<leaf>` index (skipping deleted/non-access leaves), and `printed_page` label so cache hits never re-parse XML.
21
+ - `djvu.txt`: form-feed (`\x0c`) page-delimited OCR text (taken verbatim from `_djvu.txt` when form-feed delimited, or reconstructed from `_hocr_searchtext.txt.gz` + `_hocr_pageindex.json.gz` when raw `_djvu.txt` lacks page breaks).
22
+
23
+ ### Search inside cached digitized books (`grep`)
24
+
25
+ Downloads missing metadata, `scandata.xml`, and OCR text in parallel (`max_workers=6`, `timeout=25`) on cache miss, then searches line by line (never `re.S` + `.*`) and maps every match to its exact BookReader `leaf`, `printed_page`, snippet, and direct JPEG URL:
26
+
27
+ ```bash
28
+ # Search one or more digitized books (cache miss populates ~/.cache/kinloom-ia/<id>/)
29
+ skills/archive-org/scripts/archive-org grep ourmartyrpreside00banc --pattern 'Gettysburg' --context 240 --limit 25
30
+
31
+ # Case-insensitive multi-item regex grep with structured JSON output
32
+ skills/archive-org/scripts/archive-org grep item_a item_b --pattern 'Lincoln|Douglass' -i --json
33
+ ```
34
+
35
+ ### Download single high-res pages (`page`) by printed page or leaf
36
+
37
+ Resolve printed book page numbers to exact BookReader leaves automatically via cached `page_index.json` (eliminating off-by-one leaf offsets), or pass `--leaf` / legacy positional `<leaf>` directly:
38
+
39
+ ```bash
40
+ # Resolve printed page "12" automatically and save at BookReader scale 2
41
+ skills/archive-org/scripts/archive-org page ourmartyrpreside00banc --printed-page 12 --scale 2 --out ./page12.jpg
42
+
43
+ # Fetch an explicit BookReader leaf n0 into a file or directory
44
+ skills/archive-org/scripts/archive-org page ourmartyrpreside00banc --leaf 0 --scale 2 --out ./cover.jpg
45
+ skills/archive-org/scripts/archive-org page ourmartyrpreside00banc 0 --width 1200 --out ./downloads
46
+ ```
47
+
48
+ Single-page URL patterns: `https://archive.org/download/<identifier>/page/n<leaf>_s<scale>.jpg` and `https://archive.org/download/<identifier>/page/n<leaf>_w<width>.jpg`. Returns HTTP 403 on borrow-only / `inlibrary` items.
49
+
50
+ ### Search item metadata (`search`) vs full-text OCR (`fulltext`)
51
+
52
+ `search` calls `advancedsearch.php`, which searches **item metadata only** (title, creator, description, subjects), NOT the OCR text inside digitized books. Use `fulltext` to search across books, and `grep` to search inside specific known items:
53
+
54
+ ```bash
55
+ # Metadata search: titles mentioning Lincoln
56
+ skills/archive-org/scripts/archive-org search 'title:(Lincoln)'
57
+
58
+ # Narrow metadata search to digitized texts for a historical figure
59
+ skills/archive-org/scripts/archive-org search '"Frederick Douglass"' --mediatype texts
60
+
61
+ # Sort by popularity, second page, full JSON
62
+ skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --sort 'downloads desc' --rows 5
63
+ skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --page 2
64
+ skills/archive-org/scripts/archive-org search 'title:(Lincoln)' --json
65
+
66
+ # Full-text OCR search inside digitized books (returns highlighted OCR snippets)
67
+ skills/archive-org/scripts/archive-org fulltext '"Abraham Lincoln" Gettysburg' --rows 5
68
+ skills/archive-org/scripts/archive-org fulltext '"Clara Barton" Red Cross' --json
69
+ ```
70
+
71
+ The `search` query is Lucene syntax (see below). Default returned fields are `identifier`, `title`, `creator`, `date`, `mediatype`; pass `--field` (repeatable) to change them. A zero-hit `search` means no item metadata matched; run `fulltext` before concluding a name is absent from digitized directories or county histories.
72
+
73
+ ### Read an item's metadata and files
74
+
75
+ ```bash
76
+ skills/archive-org/scripts/archive-org get <identifier>
77
+ skills/archive-org/scripts/archive-org get <identifier> --files
78
+ skills/archive-org/scripts/archive-org get <identifier> --json
79
+ ```
80
+
81
+ ### Download files
82
+
83
+ ```bash
84
+ # List an item's files first, then download the OCR text or PDF
85
+ skills/archive-org/scripts/archive-org download <identifier> --list
86
+ skills/archive-org/scripts/archive-org download <identifier> <identifier>_djvu.txt --out ./downloads
87
+ skills/archive-org/scripts/archive-org download <identifier> <identifier>.pdf --out ./downloads
88
+ ```
89
+
90
+ The CLI refuses a file name that is not in the item's file list, so list first when unsure. Download URLs follow the site's redirect to the file server automatically.
91
+
92
+ ### Build a website search URL offline
93
+
94
+ ```bash
95
+ skills/archive-org/scripts/archive-org url 'title:(Lincoln)' --mediatype texts
96
+ ```
97
+
98
+ ## Advanced Search API (verified live 2026-11-24)
99
+
100
+ - Endpoint: `GET https://archive.org/advancedsearch.php`
101
+ - Auth: none for read access. No key is normally needed.
102
+ - Required params: `q` (Lucene query), `output=json`. Common params: `fl[]` (repeatable field list), `rows` (results per page, default 50), `page` (page number), `sort[]` (repeatable, e.g. `downloads desc`, `date asc`).
103
+ - Response shape: `{ responseHeader: { status: 0, QTime }, response: { numFound, start, docs: [...] } }`. `status: 0` means success.
104
+ - The human search UI lives at the same URL: `https://archive.org/advancedsearch.php` (interactive query builder at `https://archive.org/advancedsearch.php#raw`).
105
+ - Docs: `https://archive.org/help/json.php` and `https://archive.org/developers/index-apis.html`.
106
+
107
+ ### Lucene query syntax (verified live)
108
+
109
+ - Fielded: `title:(Lincoln)`, `creator:(Douglass)`, `mediatype:(texts)`, `collection:(...)`, `year:1895`.
110
+ - Boolean: `title:(Lincoln) AND mediatype:(texts)`, `OR`, `NOT`, parentheses for grouping.
111
+ - Exact phrase: `"Clara Barton"`.
112
+ - Wildcard: `Clemens*`.
113
+ - Plain keywords match broadly across fields; quote exact names and use fielded queries to narrow results.
114
+
115
+ ## Metadata API (verified live 2026-11-24)
116
+
117
+ - Endpoint: `GET https://archive.org/metadata/<identifier>`
118
+ - Auth: none. Returns JSON with `metadata` (title, creator, date, mediatype, collection, description, subject) and `files` (each with `name`, `format`, `size`, `md5`, `sha1`, `mtime`, `source`).
119
+ - Item page: `https://archive.org/details/<identifier>` (the metadata endpoint is the same path with `/details/` swapped to `/metadata/`).
120
+
121
+ ## File download (verified live 2026-11-24)
122
+
123
+ - Pattern: `GET https://archive.org/download/<identifier>/<filename>` (follows a redirect to the file server; the CLI follows it).
124
+ - Common derivative files for a scanned book: `<id>.pdf` (full scan), `<id>_djvu.txt` (OCR text), `<id>_djvu.xml`, `<id>_files.xml` (file inventory), `<id>_meta.sqlite`. Always list the item's files first; not every derivative exists for every item.
125
+ - Be a good citizen: download only the files the research needs, one item at a time. Do not bulk-mirror collections. Uploads and writes need an account and are out of scope for this skill.
126
+
127
+ ## Environment variables
128
+
129
+ - `KINLOOM_IA_CACHE_DIR` (optional): overrides the default `~/.cache/kinloom-ia` cache directory used by `grep` and `page`. No API key or login is required.