From d12d04c3ab9b13fd6365deab0f154bbe96e6bca7 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Thu, 7 Aug 2025 00:37:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B7=B1=E5=9C=B3?= =?UTF-8?q?=E5=8F=B0=E9=A3=8E=E7=BD=91=E6=B7=B1=E5=9C=B3=E5=A4=A9=E6=B0=94?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=20(#19766)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/121/namespace.ts | 9 ++ lib/routes/121/templates/description.art | 17 ++++ lib/routes/121/weather-live.ts | 104 +++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 lib/routes/121/namespace.ts create mode 100644 lib/routes/121/templates/description.art create mode 100644 lib/routes/121/weather-live.ts diff --git a/lib/routes/121/namespace.ts b/lib/routes/121/namespace.ts new file mode 100644 index 000000000..509efb187 --- /dev/null +++ b/lib/routes/121/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '深圳台风网', + url: '121.com.cn', + categories: ['forecast'], + description: '', + lang: 'zh-CN', +}; diff --git a/lib/routes/121/templates/description.art b/lib/routes/121/templates/description.art new file mode 100644 index 000000000..7fdb805f8 --- /dev/null +++ b/lib/routes/121/templates/description.art @@ -0,0 +1,17 @@ +{{ if description }} +

{{ description }}

+{{ /if }} + +{{ if images }} + {{ each images image }} + {{ if image?.src }} +
+ {{ image.alt }} +
+ {{ /if }} + {{ /each }} +{{ /if }} \ No newline at end of file diff --git a/lib/routes/121/weather-live.ts b/lib/routes/121/weather-live.ts new file mode 100644 index 000000000..f95a77cdf --- /dev/null +++ b/lib/routes/121/weather-live.ts @@ -0,0 +1,104 @@ +import { type Data, type DataItem, type Route, ViewType } from '@/types'; + +import { art } from '@/utils/render'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +import { type CheerioAPI, load } from 'cheerio'; +import { type Context } from 'hono'; +import path from 'node:path'; + +export const handler = async (ctx: Context): Promise => { + const limit: number = Number.parseInt(ctx.req.query('limit') ?? '100', 10); + + const baseUrl: string = 'https://tf.121.com.cn'; + const imgBaseUrl: string = 'https://wx.121.com.cn'; + const targetUrl: string = new URL('web/weatherLive/', baseUrl).href; + const apiUrl: string = new URL('weather/weibo/message.js', baseUrl).href; + + const targetResponse = await ofetch(targetUrl); + const $: CheerioAPI = load(targetResponse); + const language = $('html').attr('lang') ?? 'zh'; + + const response = await ofetch(apiUrl); + const messages = await response.text(); + + const items: DataItem[] = JSON.parse(messages.split(/var\smessage=/).pop()) + .slice(0, limit) + .map((item): DataItem => { + const title: string = item.Title; + const description: string | undefined = art(path.join(__dirname, 'templates/description.art'), { + description: item.Content, + images: item.Img?.map((img: string) => ({ + src: new URL(`WeChat/data/weiweb/images/lwspic/${img}`, imgBaseUrl).href, + alt: title, + })), + }); + const pubDate: number | string = item.DDatetime; + const linkUrl: string | undefined = targetUrl; + const guid: string = `121-${title}-${pubDate}`; + const image: string | undefined = item.Img?.length > 0 ? new URL(`WeChat/data/weiweb/images/lwspic/${item.Img[0]}`, imgBaseUrl).href : undefined; + const updated: number | string = pubDate; + + const processedItem: DataItem = { + title, + description, + pubDate: pubDate ? parseDate(pubDate) : undefined, + link: linkUrl ?? new URL(item.id, baseUrl).href, + guid, + id: guid, + content: { + html: description, + text: description, + }, + image, + banner: image, + updated: updated ? parseDate(updated) : undefined, + language, + }; + + return processedItem; + }); + + const title: string = $('title').text(); + + return { + title, + description: title, + link: targetUrl, + item: items, + allowEmpty: true, + image: $('img').first().attr('src') ? new URL($('img').first().attr('src') as string, baseUrl).href : undefined, + author: $('div#webnameDiv').text(), + language, + id: targetUrl, + }; +}; + +export const route: Route = { + path: '/weatherLive', + name: '深圳天气直播', + url: 'tf.121.com.cn', + maintainers: ['nczitzk'], + handler, + example: '/121/weatherLive', + parameters: undefined, + description: undefined, + 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, +};