From 4ca2c8cdc4711627f1fb59bb515d2fa1ffc1b46d Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 21 Feb 2023 12:25:32 -0400 Subject: [PATCH] feat(route): moe (#11926) --- docs/government.md | 4 ++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/moe/moe.js | 8 ++++---- lib/v2/gov/moe/s78.js | 44 ++++++++++++++++++++++++++++++++++++++++ lib/v2/gov/radar.js | 6 ++++++ lib/v2/gov/router.js | 1 + 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 lib/v2/gov/moe/s78.js diff --git a/docs/government.md b/docs/government.md index 7fa2afacb..e39c49b8a 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1474,6 +1474,10 @@ pageClass: routes +### 司局通知 + + + ## 中华人民共和国农业农村部 ### 新闻 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 502d0bbf2..db91bcd2b 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -23,6 +23,7 @@ module.exports = { '/miit/wjgs': ['Yoge-Code'], '/miit/zcjd': ['Yoge-Code'], '/moe/:type': ['Crawler995'], + '/moe/s78/:column': ['TonyRL'], '/mofcom/article/:suffix+': ['LogicJake'], '/moj/aac/news/:type?': ['TonyRL'], '/nifdc/:path+': ['nczitzk'], diff --git a/lib/v2/gov/moe/moe.js b/lib/v2/gov/moe/moe.js index 8c3864413..feb773f41 100644 --- a/lib/v2/gov/moe/moe.js +++ b/lib/v2/gov/moe/moe.js @@ -17,10 +17,10 @@ module.exports = async (ctx) => { let id = ''; let name = ''; - for (let i = 0; i < typesIdMap.length; i++) { - if (typesIdMap[i].type === type) { - id = typesIdMap[i].id; - name = typesIdMap[i].name; + for (const item of typesIdMap) { + if (item.type === type) { + id = item.id; + name = item.name; } } diff --git a/lib/v2/gov/moe/s78.js b/lib/v2/gov/moe/s78.js new file mode 100644 index 000000000..661849591 --- /dev/null +++ b/lib/v2/gov/moe/s78.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const baseUrl = 'https://www.moe.gov.cn'; + const { column } = ctx.params; + const link = `${baseUrl}/s78/${column}/tongzhi/`; + + const { data: response } = await got(link); + const $ = cheerio.load(response); + + const list = $('#list li') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').attr('title'), + link: new URL(item.find('a').attr('href'), link).href, + pubDate: timezone(parseDate(item.find('span').text(), 'YYYY-MM-DD'), +8), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + $('#moe-detail-page-set, #moeCode, .moe-detail-shuxing, h1').remove(); + item.description = $('.moe-detail-box').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('meta[name="ColumnType"]').attr('content')} - ${$('head title').text()}`, + link, + item: items, + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index c56545129..d6928a592 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -681,6 +681,12 @@ module.exports = { source: ['/'], target: '/gov/moe/newest_file', }, + { + title: '司局通知', + docs: 'https://docs.rsshub.app/government.html#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu', + source: ['/s78/:column/tongzhi', '/s78/:column'], + target: '/gov/moe/s78/:column', + }, ], }, 'mofcom.gov.cn': { diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 6c44873bd..d6e360fc1 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -15,6 +15,7 @@ module.exports = function (router) { router.get('/miit/wjgs', require('./miit/wjgs')); router.get('/miit/zcjd', require('./miit/zcjd')); router.get('/moe/:type', require('./moe/moe')); + router.get('/moe/s78/:column', require('./moe/s78')); router.get('/mofcom/article/:suffix+', require('./mofcom/article')); router.get('/moj/aac/news/:type?', require('./moj/aac/news')); router.get(/nifdc\/([\w/-]+)?/, require('./nifdc'));