Unlisted
Script
October 23, 2023
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
import { post_to_bsky } from "https://esm.town/v/fil/post_to_bsky";
import { parseFeed } from "https://esm.town/v/fil/parseFeed";
export async function bsky_rss_poll(feedUrl, storage, identifier, password) {
const entries = await parseFeed(feedUrl);
const title = unescapeHTML(entries[0].text);
const url = entries[0].link;
if (!title)
return;
const latest_rss = String(url);
if (storage[feedUrl] !== latest_rss) {
storage[feedUrl] = latest_rss;
const post = `${String(title).substring(0, 200)}${
String(title).length > 201 ? "…" : ""
}
${url} `;
return await post_to_bsky(post, identifier, password);
}
// Quick and dirty html tag strip, for when we use the description payload
// TODO: fine tune.
function unescapeHTML(str) {
return String(str).replace(/&|<|>|'|"/g, (tag) => ({
"&": "&",
"<": "<",
">": ">",
"'": "'",
""": '"',
}[tag] || tag)).replace(/<[^>]*>/g, "");
}
}
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