From 4b9844b67ed4ef26ad9aff2109fb4353f8429280 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Thu, 10 Feb 2022 21:54:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=83=A0=E5=B7=9E?= =?UTF-8?q?=E5=B8=82=E6=94=BF=E5=BA=9C=E6=83=A0=E5=B7=9E=E6=97=B6=E6=94=BF?= =?UTF-8?q?=20(#9065)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 惠州市政府惠州时政 * fix(route): fix typo * fix(route): remove redundant code * fix(route): fix timezone --- docs/government.md | 6 ++++ lib/v2/gov/huizhou/zwgk/index.js | 58 ++++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 35 +++++++++++++++++++ lib/v2/gov/router.js | 1 + 5 files changed, 101 insertions(+) create mode 100644 lib/v2/gov/huizhou/zwgk/index.js diff --git a/docs/government.md b/docs/government.md index 65b502967..3aa08f8c7 100644 --- a/docs/government.md +++ b/docs/government.md @@ -128,6 +128,12 @@ pageClass: routes +### 惠州市人民政府 + +#### 政务公开 + + + ## 国家税务总局 ### 最新文件 diff --git a/lib/v2/gov/huizhou/zwgk/index.js b/lib/v2/gov/huizhou/zwgk/index.js new file mode 100644 index 000000000..abe5d4afc --- /dev/null +++ b/lib/v2/gov/huizhou/zwgk/index.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootURL = 'http://www.huizhou.gov.cn'; + +module.exports = async (ctx) => { + const cate = ctx.params.category ?? 'zwyw'; + const url = `${rootURL}/zwgk/hzsz/${cate}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('span#navigation').children('a').last().text(); + const list = $('ul.ul_art_row') + .map((_, item) => ({ + title: $(item).find('a').text().trim(), + link: $(item).find('a').attr('href'), + pubDate: timezone(parseDate($(item).find('li.li_art_date').text().trim()), +8), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + try { + item.description = content('div.artContent').html(); + item.author = content('div.info_fbt') + .find('span.ly') + .text() + .match(/来源:(.*)/)[1]; + item.pubDate = timezone( + parseDate( + content('div.info_fbt') + .find('span.time') + .text() + .match(/时间:(.*)/)[1] + ), + +8 + ); + } catch (e) { + item.description = ''; + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: `惠州市人民政府 - ${title}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 6387bce05..3c8b3f0b1 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -5,4 +5,5 @@ module.exports = { '/shanghai/rsj/ksxm': ['Fatpandac'], '/guangdong/tqyb/tfxtq': ['Fatpandac'], '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], + '/huizhou/zwgk/:category?': ['Fatpandac'], }; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 25eda4bfe..1ffc68813 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -330,4 +330,39 @@ module.exports = { }, ], }, + 'huizhou.gov.cn': { + _name: '惠州市人民政府', + www: [ + { + title: '政务公开 - 政务要闻', + docs: 'https://docs.rsshub.app/government.html#guang-yan-an-dong-sheng-xing-xian-ren-min-zheng-zheng-fu-hui-zhou-shi-fu-ren-min-zheng-zheng-fu-zheng-zheng-wu-gong-kai', + source: ['/zwgk/hzsz/:category'], + target: (params) => { + if (params.category === 'zwyw') { + return '/gov/huizhou/zwgk/zwyw'; + } + }, + }, + { + title: '政务公开 - 机关动态', + docs: 'https://docs.rsshub.app/government.html#guang-yan-an-dong-sheng-xing-xian-ren-min-zheng-zheng-fu-hui-zhou-shi-fu-ren-min-zheng-zheng-fu-zheng-zheng-wu-gong-kai', + source: ['/zwgk/hzsz/:category'], + target: (params) => { + if (params.category === 'jgdt') { + return '/gov/huizhou/zwgk/jgdt'; + } + }, + }, + { + title: '政务公开 - 县区要闻', + docs: 'https://docs.rsshub.app/government.html#guang-yan-an-dong-sheng-xing-xian-ren-min-zheng-zheng-fu-hui-zhou-shi-fu-ren-min-zheng-zheng-fu-zheng-zheng-wu-gong-kai', + source: ['/zwgk/hzsz/:category'], + target: (params) => { + if (params.category === 'xqyw') { + return '/gov/huizhou/zwgk/xqyw'; + } + }, + }, + ], + }, }; diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 732d91085..7e6639c26 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -6,4 +6,5 @@ module.exports = function (router) { router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb')); router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq')); router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh')); + router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index')); };