feat: read feed URLs from file

This commit is contained in:
2025-06-04 11:44:03 +09:00
parent 7caaa164a8
commit 80d48a1f8c
2 changed files with 29 additions and 4 deletions

View File

@ -12,9 +12,28 @@ interface FeedItem {
contentSnippet?: string;
}
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function main() {
const parser = new Parser<FeedItem>();
const feedUrls = ["https://example.com/feed1.rss"];
const feedUrlsFile = process.env.FEED_URLS_FILE ?? "feed_urls.txt";
const feedUrlsPath = path.resolve(__dirname, "..", feedUrlsFile);
let feedUrls: string[];
try {
const data = await fs.readFile(feedUrlsPath, "utf-8");
feedUrls = data
.split("\n")
.map((url) => url.trim())
.filter((url) => url.length > 0);
} catch (err) {
console.warn(`フィードURLファイルの読み込みに失敗: ${feedUrlsFile}`);
feedUrls = [];
}
for (const url of feedUrls) {
const feed = await parser.parseURL(url);
@ -29,7 +48,7 @@ async function main() {
pub.getMonth() === yesterday.getMonth() &&
pub.getDate() === yesterday.getDate()
) {
const already = await markAsProcessed(url, item['id'] as string);
const already = await markAsProcessed(url, item["id"] as string);
if (already) continue;
const scriptText = await openAI_GenerateScript({
@ -37,10 +56,13 @@ async function main() {
link: item.link ?? "",
contentSnippet: item.contentSnippet ?? "",
});
const audioFilePath = await generateTTS(item['id'] as string, scriptText);
const audioFilePath = await generateTTS(
item["id"] as string,
scriptText,
);
await saveEpisode({
id: item['id'] as string,
id: item["id"] as string,
title: item.title ?? "",
pubDate: pub.toISOString(),
audioPath: audioFilePath,