1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { chunk as chunk2 } from "https://esm.town/v/iakovos/chunk";
import { fetchAndParseFeeds } from "https://esm.town/v/iakovos/fetchAndParseFeeds";
import { lastRunAt } from "https://esm.town/v/iakovos/lastRunAt";
import { rssFeeds } from "https://esm.town/v/iakovos/rssFeeds";
export async function pollRSSFeeds() {
let allNewItems = [];
const rssFeedChunks = chunk2(rssFeeds, 25);
for (const chunk of rssFeedChunks) {
await Promise.all(chunk.map(async ({ name, url, type }) => {
try {
const feeds = await fetchAndParseFeeds(url) || [];
const newFeeds = feeds.filter(({ pubDate }) =>
lastRunAt
&& new Date(pubDate) > new Date(lastRunAt)
).map((item) => ({ ...item, type }));
if (newFeeds.length) {
allNewItems = [...allNewItems, ...newFeeds];
}
}
catch (error) {
console.error(`Failed to fetch items for ${name}: ${error.message}!`);
}
}));
}
return allNewItems;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023