// Re-runs the one search that returned HTTP 500 during the full fetch and // appends its survivors to results/jobs.csv in the same format as index.ts. import { RESEARCH_KEYWORDS } from "../config.ts"; import { fetchJobs, isEnglishContent } from "../fetch.ts"; import type { SearchConfig } from "../config.ts"; const CSV = "./results/jobs.csv"; const config: SearchConfig = { label: "Research — Zürich Metropolitan Area", keywords: RESEARCH_KEYWORDS, geoId: "107814425", location: "Zürich Metropolitan Area", workType: ["onsite", "hybrid"], timePosted: "month", }; function csvCell(val: string): string { return `"${(val ?? "").replace(/"/g, '""')}"`; } const text = await Bun.file(CSV).text(); const seen = new Set( text.split("\n").map((l) => l.match(/jobs\/view\/(\d+)/)?.[1]).filter(Boolean) as string[] ); const date = new Date().toISOString().slice(0, 10); const jobs = (await fetchJobs(config)).filter((j) => !seen.has(j.id)); const rows: string[] = []; for (const j of jobs) { if (!(await isEnglishContent(j.id))) continue; rows.push([date, j.postedAt, config.label, j.title, j.company, j.link, "linkedin.com"].map(csvCell).join(",")); } await Bun.write(CSV, text.trimEnd() + "\n" + rows.join("\n") + "\n"); console.log(`${rows.length} appended → ${CSV}`);