UNPKG

rsshub

Version:
94 lines (92 loc) 2.88 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import { t as ViewType } from "./types-D84BRIt4.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 { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/121/weather-live.ts init_esm_shims(); const handler = async (ctx) => { const limit = Number.parseInt(ctx.req.query("limit") ?? "100", 10); const baseUrl = "https://tf.121.com.cn"; const imgBaseUrl = "https://wx.121.com.cn"; const targetUrl = new URL("web/weatherLive/", baseUrl).href; const apiUrl = new URL("weather/weibo/message.js", baseUrl).href; const $ = load(await ofetch_default(targetUrl)); const language = $("html").attr("lang") ?? "zh"; const messages = await (await ofetch_default(apiUrl)).text(); const items = JSON.parse(messages.split(/var\smessage=/).pop()).slice(0, limit).map((item) => { const title$1 = item.Title; const description = art(path.join(__dirname, "templates/description-ae443df5.art"), { description: item.Content, images: item.Img?.map((img) => ({ src: new URL(`WeChat/data/weiweb/images/lwspic/${img}`, imgBaseUrl).href, alt: title$1 })) }); const pubDate = item.DDatetime; const linkUrl = targetUrl; const guid = `121-${title$1}-${pubDate}`; const image = item.Img?.length > 0 ? new URL(`WeChat/data/weiweb/images/lwspic/${item.Img[0]}`, imgBaseUrl).href : void 0; const updated = pubDate; return { title: title$1, description, pubDate: pubDate ? parseDate(pubDate) : void 0, link: linkUrl ?? new URL(item.id, baseUrl).href, guid, id: guid, content: { html: description, text: description }, image, banner: image, updated: updated ? parseDate(updated) : void 0, language }; }); const title = $("title").text(); return { title, description: title, link: targetUrl, item: items, allowEmpty: true, image: $("img").first().attr("src") ? new URL($("img").first().attr("src"), baseUrl).href : void 0, author: $("div#webnameDiv").text(), language, id: targetUrl }; }; const route = { path: "/weatherLive", name: "深圳天气直播", url: "tf.121.com.cn", maintainers: ["nczitzk"], handler, example: "/121/weatherLive", parameters: void 0, description: void 0, categories: ["forecast"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["tf.121.com.cn", "tf.121.com.cn/web/weatherLive"], target: "/weatherLive" }], view: ViewType.Notifications }; //#endregion export { handler, route };