import { email } from "https://esm.town/v/std/email?v=9";
import { rssEntriesToHTML } from "https://esm.town/v/zackoverflow/rssEntriesToHTML";
import { set } from "https://esm.town/v/std/set?v=11";
import { pollRss } from "https://esm.town/v/zackoverflow/pollRss";
import { rssEmail } from "https://esm.town/v/zackoverflow/rssEmail";
let { rssCache } = await import("https://esm.town/v/zackoverflow/rssCache");
let { rssFeeds } = await import("https://esm.town/v/zackoverflow/rssFeeds");
export const pollRssAndEmail = async () => {
rssFeeds = rssFeeds ??
["https://journal.stuffwithstuff.com/rss.xml"];
rssCache = rssCache ?? {} as any;
if (typeof rssEmail !== "string")
throw new Error(
"You haven't set your email, please create a val called @rssEmail and set its value to your e-mail address.",
);
const rssEntries = await pollRss(
rssFeeds,
rssCache,
);
await set("rssCache", rssCache);
if (rssEntries.length === 0)
return;
const html = await rssEntriesToHTML(rssEntries);
return await email({
to: [rssEmail],
subject: `RSS Update ${(new Date()).toDateString()}`,
html,
});
};