rsrsss/bin/build_nhc_opml

36 lines
1.5 KiB
Bash
Executable File

#!/bin/sh -e
node -e 'const baseUrl = "https://www.nhc.noaa.gov/aboutrss.shtml";
require("node:https").get(baseUrl, res => {
const chunks = [];
res.on("data", chunk => chunks.push(chunk));
res.on("end", () => {
process.stdout.write(JSON.stringify({
opml: {
"@version": "2.0",
head: {
title: "National Hurricane Center and Central Pacific Hurricane Center RSS feeds",
dateModified: new Date().toUTCString(),
ownerName: "lucidiot",
ownerEmail: "lucidiot@envs.net",
ownerId: "https://tilde.town/~lucidiot/contact.html",
docs: "http://dev.opml.org/spec2.html"
},
body: {
outline: Array.from(
Buffer.concat(chunks).toString("latin1").matchAll(/<a[^>]*href="[^"]+\.xml"[^>]*>\s*<img[^>]*src="[^"]*gifs\/xml.gif"[^>]*>\s*<\/a>\s*(?<name>[^<]+)<a[^>]*href="(?<url>[^"]+\.xml)"[^>]*>/gi),
({ groups: { name, url } }) => {
const text = name.replace(/[:\s]*$/g, "").replace(/&#(\d+);/, (_, code) => String.fromCharCode(parseInt(code, 10))).replace(/&(amp|gt|lt|apos|quot);/, (_, name) => ({ amp: "&", gt: ">", lt: "<", apos: "'"'"'", quot: "\"" }[name]));
return {
"@type": "rss",
"@text": text,
"@xmlUrl": new URL(url, baseUrl).href,
"@language": ["Español", "Atlantico", "Cartera"].some(word => text.includes(word)) ? "es" : "en-us"
}
},
)
}
}
}), "utf-8");
});
})' | oq -i json -o xml .