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
28
29
30
31
32
33
34
35
36
37
import { extendFeeds } from "https://esm.town/v/iakovos/extendFeeds";
import { feedLogs } from "https://esm.town/v/iakovos/feedLogs";
import { getTopScoredArticles } from "https://esm.town/v/iakovos/getTopScoredArticles";
import { interests } from "https://esm.town/v/iakovos/interests";
import { pollRSSFeeds } from "https://esm.town/v/iakovos/pollRSSFeeds";
import { renderFeedsForEmail } from "https://esm.town/v/iakovos/renderFeedsForEmail";
import { scoreAndCombineArticles } from "https://esm.town/v/iakovos/scoreAndCombineArticles";
import { email } from "https://esm.town/v/std/email?v=9";
import { set } from "https://esm.town/v/std/set?v=11";
export const pollAndEmailArticles = async () => {
const feeds = await pollRSSFeeds();
const hasFeeds = feeds?.length > 0;
if (hasFeeds) {
const extendedFeeds = extendFeeds(feeds);
const blogs = extendedFeeds.filter((feed) => feed.type === "blog");
const articles = extendedFeeds.filter((feed) => feed.type !== "blog");
const scoredArticles = await scoreAndCombineArticles(
articles,
interests,
);
const topArticles = getTopScoredArticles(scoredArticles, 35) ?? [];
const allItems = [...blogs, ...topArticles];
// const allItems = [...blogs, ...articles.slice(0, 10)];
// const html = renderFeedsForEmail(allItems);
return allItems;
// await email({ subject: "Your Daily RSS Digest", html });
// await set("lastRunAt", Date.now());
// await set("feedLogs", {
// runAt: new Date().toString(),
// articles: articles?.length ?? 0,
// blogs: blogs?.length ?? 0,
// ratedArticles: topArticles,
// });
}
};
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 30, 2023