* feat: 添加koa路由 ## Involved Issue / 该 PR 相关 Issue Close # ## Example for the Proposed Route(s) / 路由地址示例 ## New RSS Route Checklist / 新 RSS 路由检查表 - [x] New Route / 新的路由 - [x] Follows [Script Standard](https://docs.rsshub.app/joinus/advanced/script-standard) / 跟随 [路由规范](https://docs.rsshub.app/zh/joinus/advanced/script-standard) - [x] Documentation / 文档说明 - [ ] Full text / 全文获取 - [ ] Use cache / 使用缓存 - [ ] Anti-bot or rate limit / 反爬/频率限制 - [ ] If yes, do your code reflect this sign? / 如果有, 是否有对应的措施? - [ ] [Date and time](https://docs.rsshub.app/joinus/advanced/pub-date) / [日期和时间](https://docs.rsshub.app/zh/joinus/advanced/pub-date) - [ ] Parsed / 可以解析 - [ ] Correct time zone / 时区正确 - [ ] New package added / 添加了新的包 - [x] ## Note / 说明 - 新增路由暂时用于提供經香港天文台分析的全球5.0級或以上及本地有感的地震資訊。 - 后期会扩展新增新增更多其它自然公益资讯。 * try: use nodejs v20.14.0 * fix: change puppeteer to ofetch * fix: update example path * Update lib/routes/hko/app.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: use utilities to handle date and time * fix: migrate old route ---------
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { Route } from '@/types';
|
|
import ofetch from '@/utils/ofetch';
|
|
import * as cheerio from 'cheerio';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
|
|
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(url);
|
|
const $ = cheerio.load(data, {
|
|
xmlMode: true,
|
|
});
|
|
|
|
const description = $('item').first().find('description');
|
|
|
|
const $$ = cheerio.load(description.text());
|
|
|
|
const items = $$('table tr')
|
|
.toArray()
|
|
.map((item) => {
|
|
const $item = $(item);
|
|
const area = $item.find('td').first().text();
|
|
const degree = $item.find('td').last().text();
|
|
|
|
return {
|
|
title: area,
|
|
description: degree,
|
|
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,
|
|
};
|
|
};
|
|
|
|
export const route: 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',
|
|
};
|