Skip to content

Commit 21ed792

Browse files
committed
feat: default latest crawl id
1 parent 87bba2d commit 21ed792

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

apps/scraper/__tests__/db.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe.skipIf(!postgresAvailable)("db", () => {
3838
// Clean up test data from previous runs
3939
const { SQL } = await import("bun");
4040
const sql = new SQL({ url: DATABASE_URL });
41-
await sql`DELETE FROM documents`;
41+
await sql`TRUNCATE documents`;
4242
await sql.close();
4343

4444
db = await createDb(DATABASE_URL);

apps/scraper/commoncrawl/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const COLLINFO_URL = "https://index.commoncrawl.org/collinfo.json";
2+
3+
interface CrawlInfo {
4+
id: string;
5+
name: string;
6+
}
7+
8+
export async function getLatestCrawlId(): Promise<string> {
9+
const res = await fetch(COLLINFO_URL);
10+
const data = (await res.json()) as CrawlInfo[];
11+
return data[0].id;
12+
}

apps/scraper/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Commands
1515
1616
Options
1717
--batch <n> Limit to n documents (default: all)
18-
--crawl <id> Common Crawl index ID (required, or set CRAWL_ID env var)
18+
--crawl <id> Common Crawl index ID (default: latest)
1919
--force Re-process URLs already in database
2020
--verbose Show detailed logs for debugging
2121

apps/scraper/scraper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pLimit from "p-limit";
22
import { streamCdxFromR2, type CdxRecord } from "./commoncrawl/cdx-r2";
3+
import { getLatestCrawlId } from "./commoncrawl/index";
34
import { fetchWarcRecord, type WarcResult } from "./commoncrawl/warc";
45
import { type Config, hasCloudflareCredentials } from "./config";
56
import { generateManifest } from "./manifest";
@@ -124,9 +125,9 @@ export async function scrape(
124125

125126
header();
126127

127-
const crawlId = config.crawl.id;
128+
let crawlId = config.crawl.id;
128129
if (!crawlId) {
129-
throw new Error("CRAWL_ID must be specified");
130+
crawlId = await getLatestCrawlId();
130131
}
131132

132133
section("Configuration");

0 commit comments

Comments
 (0)