UNPKG

rsshub

Version:
46 lines (44 loc) 1.47 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import * as cheerio from "cheerio"; //#region lib/routes/hko/weather.ts const handler = async () => { const url = "http://rss.weather.gov.hk/rss/CurrentWeather.xml"; const pageUrl = "https://www.weather.gov.hk/en/wxinfo/currwx/current.htm"; const data = await ofetch_default(url); const $ = cheerio.load(data, { xmlMode: true }); const description = $("item").first().find("description"); const items = cheerio.load(description.text())("table tr").toArray().map((item) => { const $item = $(item); const area = $item.find("td").first().text(); return { title: area, description: $item.find("td").last().text(), pubDate: parseDate($("pubDate").text()), link: pageUrl, guid: `${$("guid").text()}#${area}` }; }); return { title: "Current Weather Report", description: `provided by the Hong Kong Observatory: ${$("pubDate").text()}`, link: pageUrl, item: items }; }; const route = { path: "/weather", radar: [{ source: ["www.weather.gov.hk/en/wxinfo/currwx/current.htm"] }], name: "Current Weather Report", example: "/hko/weather", maintainers: ["calpa"], categories: ["forecast"], handler, url: "www.weather.gov.hk/en/wxinfo/currwx/current.htm" }; //#endregion export { route };