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
import { email } from "https://esm.town/v/std/email?v=11";
import { fetchRSS } from "https://esm.town/v/stevekrouse/fetchRSS";
import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems?v=6";
import { parseXML } from "https://esm.town/v/stevekrouse/parseXML";
export default async function(interval: Interval) {
// const lastRunAt = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30 * 3);
const lastRunAt = interval.lastRunAt;
const response = await fetch("https://sive.rs/en.atom");
const xml = await response.text();
const data = await parseXML(xml);
const entries: { id: string; title: string; content: string; updated: string }[] = data.feed.entry;
const newItems = entries.filter(entry => {
return new Date(entry.updated) > new Date(lastRunAt);
});
console.log("New Items", lastRunAt, newItems);
const html = newItems.map(({ id, title, content, updated }) => {
const date = new Date(updated).toLocaleDateString();
return `<h2><a href="${id}">${title}</a> - ${date}</h2>${content}`;
}).join("\n");
if (newItems.length === 0) return;
email({ subject: `Sive.rs: ${newItems[0].title}`, html: html });
}
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!
December 26, 2023