diff --git a/docs/government.md b/docs/government.md index d2f8bb5f17..63c1c0ee78 100644 --- a/docs/government.md +++ b/docs/government.md @@ -974,9 +974,23 @@ pageClass: routes ## 中华人民共和国外交部 -### 发言人表态 +### 外交动态 - + + +| 分类 | category | +| ----- | -------- | +| 领导人活动 | gjldrhd | +| 外事日程 | wsrc | +| 部领导活动 | wjbxw | +| 业务动态 | sjxw | +| 发言人表态 | fyrbt | +| 吹风会 | cfhsl | +| 大使任免 | dsrm | +| 驻外报道 | zwbd | +| 政策解读 | zcjd | + + ## 中华人民共和国住房和城乡建设部 diff --git a/lib/router.js b/lib/router.js index b90cf4c844..df28d1e493 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1225,7 +1225,7 @@ router.get('/gov/customs/list/:gchannel', lazyloadRouteHandler('./routes/gov/cus router.get('/gov/moe/:type', lazyloadRouteHandler('./routes/gov/moe/moe')); // 中华人民共和国外交部 -router.get('/gov/fmprc/fyrbt', lazyloadRouteHandler('./routes/gov/fmprc/fyrbt')); +// router.get('/gov/fmprc/fyrbt', lazyloadRouteHandler('./routes/gov/fmprc/fyrbt')); // 中华人民共和国住房和城乡建设部 router.get('/gov/mohurd/policy', lazyloadRouteHandler('./routes/gov/mohurd/policy')); diff --git a/lib/routes/gov/fmprc/fyrbt.js b/lib/routes/gov/fmprc/fyrbt.js deleted file mode 100644 index cc58fd1d3c..0000000000 --- a/lib/routes/gov/fmprc/fyrbt.js +++ /dev/null @@ -1,24 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const util = require('./utils'); - -const host = 'https://www.fmprc.gov.cn/web/wjdt_674879/fyrbt_674889/'; - -module.exports = async (ctx) => { - const response = await got.get(host, { - responseType: 'buffer', - }); - - const $ = cheerio.load(response.data); - - const list = $('.newsBd ul li').get(); - - const result = await util.ProcessFeed(list, ctx.cache); - - ctx.state.data = { - title: '中华人民共和国外交部-发言人表态', - link: host, - description: '中华人民共和国外交部-发言人表态', - item: result, - }; -}; diff --git a/lib/routes/gov/fmprc/utils.js b/lib/routes/gov/fmprc/utils.js deleted file mode 100644 index 1b587e7128..0000000000 --- a/lib/routes/gov/fmprc/utils.js +++ /dev/null @@ -1,50 +0,0 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); - -// 加载文章页 -async function load(link) { - const response = await got.get(link); - const $ = cheerio.load(response.data); - - const date = parseDate($('.time').text(), 'YYYY-MM-DD HH:mm'); - - const pubDate = timezone(date, +8); - - // 提取内容 - const description = $('#News_Body_Txt_A').html(); - - return { description, pubDate }; -} - -const ProcessFeed = (list, caches) => { - const host = 'https://www.fmprc.gov.cn/web/wjdt_674879/fyrbt_674889/'; - - return Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - - const $title = $('a'); - // 还原相对链接为绝对链接 - const itemUrl = new URL($title.attr('href'), host); - - // 列表上提取到的信息 - const single = { - title: $.text(), - link: itemUrl, - }; - - // 使用tryGet方法从缓存获取内容。 - // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); - - // 合并解析后的结果集作为该篇文章最终的输出结果 - return { ...single, ...other }; - }) - ); -}; - -module.exports = { - ProcessFeed, -}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 8a8355f99d..ba7147a098 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -3,10 +3,12 @@ module.exports = { '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], '/shenzhen/zzb/:caty/:page?': ['zlasd'], '/shanghai/rsj/ksxm': ['Fatpandac'], + '/fmprc/:category?': ['nicolaszf', 'nczitzk'], '/guangdong/tqyb/tfxtq': ['Fatpandac'], '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], '/huizhou/zwgk/:category?': ['Fatpandac'], '/sichuan/deyang/govpulicinfo/:countyName/:institutionName?': ['zytomorrow'], + '/mfa/wjdt/:category?': ['nczitzk'], '/miit/wjfb/:ministry': ['Fatpandac'], '/miit/yjzj': ['Fatpandac'], '/miit/zcwj': ['Yoge-Code'], diff --git a/lib/v2/gov/mfa/wjdt.js b/lib/v2/gov/mfa/wjdt.js new file mode 100644 index 0000000000..b95b22dcc4 --- /dev/null +++ b/lib/v2/gov/mfa/wjdt.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +const categories = { + gjldrhd: 'gjldrhd_674881', + wsrc: 'wsrc_674883', + wjbxw: 'wjbxw_674885', + sjxw: 'sjxw_674887', + fyrbt: 'fyrbt_674889', + cfhsl: 'cfhsl_674891', + dsrm: 'dsrm_674893', + zwbd: 'zwbd_674895', + zcjd: 'zcjd', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'gjldrhd'; + + const rootUrl = 'https://www.mfa.gov.cn'; + const currentUrl = `${rootUrl}/web/wjdt_674879/${categories[category]}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('ul.list1 li a') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 35) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href').replace(/^\./, currentUrl), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('#News_Body_Txt_A').html(); + item.pubDate = timezone(parseDate(content('.time span').last().text()), +8); + item.category = content('meta[name="Keywords"]').attr('content')?.split(';') ?? []; + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 355d63b0d6..d3c3ec4075 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -433,4 +433,15 @@ module.exports = { }, ], }, + 'mfa.gov.cn': { + _name: '中华人民共和国外交部', + www: [ + { + title: '外交动态', + docs: 'https://docs.rsshub.app/government.html#zhong-hua-ren-min-gong-he-guo-wai-jiao-bu-wai-jiao-dong-tai', + source: ['/web/wjdt_674879/:category'], + target: (params) => `/gov/mfa/wjdt/${params.category.split('_')[0]}`, + }, + ], + }, }; diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index bce3d95478..6756683f92 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -4,10 +4,12 @@ module.exports = function (router) { router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm')); router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb')); + router.get('/fmprc/:category?', require('./mfa/wjdt')); 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')); router.get('/sichuan/deyang/govpulicinfo/:countyName/:institutionName?', require('./sichuan/deyang/govpulicinfo')); + router.get('/mfa/wjdt/:category?', require('./mfa/wjdt')); router.get('/miit/wjfb/:ministry', require('./miit/wjfb')); router.get('/miit/yjzj', require('./miit/yjzj')); router.get('/miit/zcwj', require('./miit/zcwj'));