From 080d47ab01d402c08af69eeef0e872d014badb75 Mon Sep 17 00:00:00 2001 From: Satsuki Akiba Date: Sun, 8 Jun 2025 19:32:42 +0900 Subject: [PATCH] Fix --- scripts/fetch_and_generate.ts | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/scripts/fetch_and_generate.ts b/scripts/fetch_and_generate.ts index 29be973..8ce9fa9 100644 --- a/scripts/fetch_and_generate.ts +++ b/scripts/fetch_and_generate.ts @@ -43,7 +43,11 @@ export async function batchProcess(abortSignal?: AbortSignal): Promise { } // Load feed URLs from file - const feedUrls = await loadFeedUrls(); + const { fetchActiveFeeds } = await import("../services/database.js"); + + const feeds = await fetchActiveFeeds(); + const feedUrls = feeds.map((feed) => feed.url).filter((url) => !!url); + if (feedUrls.length === 0) { console.log("â„šī¸ No feed URLs found."); return; @@ -100,25 +104,6 @@ export async function batchProcess(abortSignal?: AbortSignal): Promise { } } -/** - * Load feed URLs from configuration file - */ -async function loadFeedUrls(): Promise { - try { - const data = await fs.readFile(config.paths.feedUrlsFile, "utf-8"); - return data - .split("\n") - .map((url) => url.trim()) - .filter((url) => url.length > 0 && !url.startsWith("#")); - } catch (err) { - console.warn( - `âš ī¸ Failed to read feed URLs file: ${config.paths.feedUrlsFile}`, - ); - console.warn("📝 Please create the file with one RSS URL per line."); - return []; - } -} - /** * Process a single feed URL and discover new articles */ @@ -720,13 +705,13 @@ export async function addNewFeedUrl(feedUrl: string): Promise { // Parse RSS feed to get feed information including title const parser = new Parser(); const feed = await parser.parseURL(feedUrl); - + // Extract feed title, fallback to URL if not available const feedTitle = feed.title || feedUrl; - + // Classify feed category using OpenAI const category = await openAI_ClassifyFeed(feedTitle); - + // Add to feeds table with title and category await saveFeed({ url: feedUrl, @@ -735,7 +720,9 @@ export async function addNewFeedUrl(feedUrl: string): Promise { active: true, }); - console.log(`✅ Feed URL added: ${feedUrl} (Title: ${feedTitle}, Category: ${category})`); + console.log( + `✅ Feed URL added: ${feedUrl} (Title: ${feedTitle}, Category: ${category})`, + ); } catch (error) { console.error(`❌ Failed to add feed URL: ${feedUrl}`, error); throw error;