This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

papers / scripts / poll-and-summarize.ts
1.9 kB 57 lines
1/** 2 * CLI script: poll the Paper Skygest feed and generate summaries. 3 * 4 * Usage: 5 * bun scripts/poll-and-summarize.ts # poll and write to PDS 6 * bun scripts/poll-and-summarize.ts --dry-run # show what would be processed 7 * bun scripts/poll-and-summarize.ts --limit 5 # only process 5 papers 8 */ 9 10import { pollNewPapers } from "../src/feed-watcher.js"; 11import { buildSummary } from "../src/paper-summarizer.js"; 12import { writeSummaryToPds } from "../src/pds-writer.js"; 13 14const args = process.argv.slice(2); 15const dryRun = args.includes("--dry-run"); 16const limitArg = args.find(a => a.startsWith("--limit=")); 17const limit = limitArg ? parseInt(limitArg.split("=")[1]) : Infinity; 18 19async function main() { 20 console.log("Polling Paper Skygest feed..."); 21 const { posts, newCursor } = await pollNewPapers(); 22 23 console.log(`Found ${posts.length} paper posts`); 24 25 const toProcess = posts.slice(0, limit); 26 console.log(`Processing ${toProcess.length} papers${dryRun ? " (dry-run)" : ""}...`); 27 28 let written = 0; 29 let errors = 0; 30 31 for (const post of toProcess) { 32 console.log(`\n ${post.paperUrl}`); 33 console.log(` Title: ${post.embedTitle || "(from post text)"}`); 34 console.log(` Poster: @${post.posterHandle}`); 35 36 if (dryRun) continue; 37 38 try { 39 const summary = await buildSummary(post); 40 console.log(` Summary: ${summary.summary.substring(0, 100)}...`); 41 const result = await writeSummaryToPds(post, summary); 42 console.log(` Written: ${result.uri}`); 43 written++; 44 } catch (err: any) { 45 console.error(` Error: ${err?.message ?? err}`); 46 errors++; 47 } 48 } 49 50 console.log(`\nDone. Written: ${written}, Errors: ${errors}`); 51 if (newCursor) console.log(`Next cursor: ${newCursor}`); 52} 53 54main().catch(err => { 55 console.error("Fatal:", err instanceof Error ? err.message : String(err)); 56 process.exit(1); 57});