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
import { postToMastodon } from "https://esm.town/v/sebdd/postToMastodon";
import process from "node:process";
const found = new Set();
export async function tootLatestPosts(interval: Partial<Interval>) {
const { lastRunAt = "2023-04-04T00:00:00" } = interval || {};
const lastRunDate = new Date(lastRunAt);
const out = (await Promise.all([
"https://jaandrle.github.io/feeds/nondev.xml",
"https://jaandrle.github.io/feeds/dev.xml",
].map(fetchRSS)))
.flatMap(rss =>
rss.entry
.filter(e => new Date(e.updated) > lastRunDate)
)
.filter(e => {
const f = !found.has(e.id);
if (f) found.add(e.id);
return f;
});
console.log(out);
return out;
}
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
import { parseXML } from "https://esm.town/v/stevekrouse/parseXML";
function fetchRSS(url) {
return fetchText(url)
.then(parseXML)
.then(xml => {
const out = xml.rss || xml.feed;
if (!out) throw new Error("Parsing RSS failed (no `rss` or `feed` entry)\n" + xml);
return out;
});
}
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!
April 4, 2024