From 42ff32c757c189ed4ae8b72dd68b4203c9c8cec6 Mon Sep 17 00:00:00 2001 From: Hank Chow <280630620@qq.com> Date: Fri, 19 May 2023 00:14:18 +0800 Subject: [PATCH] feat(route): add Guangzhou Metro (#12533) * feat(route): add Guangzhou Metro * fix: shorthand type conversions * fix: update as comments --- docs/en/travel.md | 6 +++++ docs/travel.md | 6 +++++ lib/v2/guangzhoumetro/maintainer.js | 3 +++ lib/v2/guangzhoumetro/news.js | 37 +++++++++++++++++++++++++++++ lib/v2/guangzhoumetro/radar.js | 11 +++++++++ lib/v2/guangzhoumetro/router.js | 3 +++ 6 files changed, 66 insertions(+) create mode 100644 lib/v2/guangzhoumetro/maintainer.js create mode 100644 lib/v2/guangzhoumetro/news.js create mode 100644 lib/v2/guangzhoumetro/radar.js create mode 100644 lib/v2/guangzhoumetro/router.js diff --git a/docs/en/travel.md b/docs/en/travel.md index 5b198a85e..ff3ef1530 100644 --- a/docs/en/travel.md +++ b/docs/en/travel.md @@ -28,6 +28,12 @@ If the city name contains a space like `Mexico City`, replace the space with `%2 :paramsDesc="['state of the exhibition: `current`,`past`, or `upcoming`, the default value is `current`']" /> +## Guangzhou Metro + +### News + + + ## Hopper ### Flight Deals diff --git a/docs/travel.md b/docs/travel.md index 941f611be..696ebaa9e 100644 --- a/docs/travel.md +++ b/docs/travel.md @@ -89,6 +89,12 @@ IATA 国际航空运输协会机场代码,参见[维基百科 国际航空运 +## 广州地铁 + +### 新闻 + + + ## 国家地理 ### 分类 diff --git a/lib/v2/guangzhoumetro/maintainer.js b/lib/v2/guangzhoumetro/maintainer.js new file mode 100644 index 000000000..601d6bea8 --- /dev/null +++ b/lib/v2/guangzhoumetro/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['HankChow'], +}; diff --git a/lib/v2/guangzhoumetro/news.js b/lib/v2/guangzhoumetro/news.js new file mode 100644 index 000000000..fd5719ced --- /dev/null +++ b/lib/v2/guangzhoumetro/news.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const newsUrl = 'https://www.gzmtr.com/ygwm/xwzx/gsxw/'; + const response = await got(newsUrl); + const data = response.data; + + const $ = cheerio.load(data); + const list = $('ul.ag_h_w li') + .map((_, item) => { + item = $(item); + const url = newsUrl + item.find('a').attr('href').substr(2); + const title = item.find('a').text(); + const publishTime = parseDate(item.find('span').text()); + return { + title, + link: url, + author: '广州地铁', + pubtime: publishTime, + }; + }) + .get(); + + ctx.state.data = { + title: '广州地铁新闻', + url: newsUrl, + description: '广州地铁新闻', + item: list.map((item) => ({ + title: item.title, + pubDate: item.pubtime, + link: item.link, + author: item.author, + })), + }; +}; diff --git a/lib/v2/guangzhoumetro/radar.js b/lib/v2/guangzhoumetro/radar.js new file mode 100644 index 000000000..94fc1bac8 --- /dev/null +++ b/lib/v2/guangzhoumetro/radar.js @@ -0,0 +1,11 @@ +module.exports = { + 'gzmtr.com': { + _name: '广州地铁', + www: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/travel.html#guang-zhou-di-tie', + }, + ], + }, +}; diff --git a/lib/v2/guangzhoumetro/router.js b/lib/v2/guangzhoumetro/router.js new file mode 100644 index 000000000..69a5972f6 --- /dev/null +++ b/lib/v2/guangzhoumetro/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news', require('./news')); +};