diff --git a/lib/router.js b/lib/router.js index 3e78f10e4..36a357b75 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1047,8 +1047,8 @@ router.get('/im2maker/:channel?', lazyloadRouteHandler('./routes/im2maker/index' router.get('/cninfo/announcement/:column/:code/:orgId/:category?/:search?', lazyloadRouteHandler('./routes/cninfo/announcement')); // 中华人民共和国农业农村部 -router.get('/gov/moa/sjzxfb', lazyloadRouteHandler('./routes/gov/moa/sjzxfb')); -router.get('/gov/moa/:suburl(.*)', lazyloadRouteHandler('./routes/gov/moa/moa')); +// router.get('/gov/moa/sjzxfb', lazyloadRouteHandler('./routes/gov/moa/sjzxfb')); +// router.get('/gov/moa/:suburl(.*)', lazyloadRouteHandler('./routes/gov/moa/moa')); // 香水时代 router.get('/nosetime/:id/:type/:sort?', lazyloadRouteHandler('./routes/nosetime/comment')); diff --git a/lib/routes/gov/moa/sjzxfb.js b/lib/routes/gov/moa/sjzxfb.js deleted file mode 100644 index c9058775d..000000000 --- a/lib/routes/gov/moa/sjzxfb.js +++ /dev/null @@ -1,20 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: `http://zdscxx.moa.gov.cn:8080/misportal/echartReport/webData/%E6%9C%80%E6%96%B0%E5%8F%91%E5%B8%83/page1.json`, - }); - const data = response.data; - - ctx.state.data = { - title: '中华人民共和国农业农村部 - 数据 - 最新发布', - link: `http://zdscxx.moa.gov.cn:8080/nyb/pc/index.jsp`, - item: data.map((item) => ({ - title: item.title, - description: item.content, - link: `http://zdscxx.moa.gov.cn:8080/misportal/public/agricultureMessageViewDC.jsp?page=1&channel=%E6%9C%80%E6%96%B0%E5%8F%91%E5%B8%83&id=${item._id}`, - pubDate: new Date(item.publishTime), - })), - }; -}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index b743963c3..b2c1bc1b9 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -29,6 +29,8 @@ module.exports = { '/miit/zcwj': ['Yoge-Code'], '/miit/wjgs': ['Yoge-Code'], '/miit/zcjd': ['Yoge-Code'], + '/moa/zdscxx/:channel?/:source?': ['MisteryMonster', 'nczitzk'], + '/moa/:suburl': ['Origami404'], '/moe/:type': ['Crawler995'], '/moe/s78/:column': ['TonyRL'], '/mofcom/article/:suffix+': ['LogicJake'], diff --git a/lib/routes/gov/moa/moa.js b/lib/v2/gov/moa/moa.js similarity index 100% rename from lib/routes/gov/moa/moa.js rename to lib/v2/gov/moa/moa.js diff --git a/lib/v2/gov/moa/zdscxx.js b/lib/v2/gov/moa/zdscxx.js new file mode 100644 index 000000000..d37cd20bc --- /dev/null +++ b/lib/v2/gov/moa/zdscxx.js @@ -0,0 +1,104 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 5; + + const domain = 'moa.gov.cn'; + const rootFrameUrl = `http://www.${domain}`; + const rootUrl = `http://zdscxx.${domain}:8080`; + const apiUrl = new URL('nyb/getMessages', rootUrl).href; + const apiDetailUrl = new URL('nyb/getMessagesById', rootUrl).href; + const currentUrl = new URL('nyb/pc/messageList.jsp', rootUrl).href; + const frameUrl = new URL('iframe/top_sj', rootFrameUrl).href; + + let filterForm = {}; + + if (category) { + const apiFilterUrl = new URL('nyb/getMessageFilters', rootUrl).href; + + const { data: filterResponse } = await got.post(apiFilterUrl, { + form: { + type: '', + isLatestMessage: false, + }, + }); + + const filters = filterResponse.result.reduce((filters, f) => { + filters[f.name] = f.data.map((d) => d.name); + return filters; + }, {}); + + filterForm = category.split(/\//).reduce((form, c) => { + Object.keys(filters) + .filter((key) => filters[key].includes(c)) + .forEach((key) => { + form[key] = c; + }); + return form; + }, {}); + } + + const { data: response } = await got.post(apiUrl, { + form: { + page: 1, + rows: limit, + type: '', + isLatestMessage: false, + ...filterForm, + }, + }); + + let items = response.result.table.slice(0, limit).map((item) => ({ + title: item.title, + link: item.id, + guid: `moa-zdscxx-${item.id}`, + pubDate: parseDate(item.date), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.guid, async () => { + const { data: detailResponse } = await got.post(apiDetailUrl, { + form: { + id: item.link, + }, + }); + + const data = detailResponse.result; + + item.title = data.title; + item.link = new URL(`nyb/pc/messageView.jsp?id=${item.link}`, rootUrl).href; + item.description = data.content; + item.author = data.source; + item.pubDate = parseDate(data.date); + + return item; + }) + ) + ); + + const { data: frameResponse } = await got(frameUrl); + + const $ = cheerio.load(frameResponse); + + const title = $('title').text(); + const description = '数据'; + const icon = new URL('favicon.ico', rootUrl).href; + + ctx.state.data = { + item: items, + title: `${title} - ${description} - ${category}`, + link: currentUrl, + description, + language: 'zh', + image: $('h1.logo a img').prop('src'), + icon, + logo: icon, + subtitle: category, + author: title, + allowEmpty: true, + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 38e3447bd..13bd7aef2 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -816,6 +816,35 @@ module.exports = { }, ], }, + 'moa.gov.cn': { + _name: '中华人民共和国农业农村部', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu-xin-wen', + source: ['/'], + target: '/gov/moa/:suburl', + }, + ], + zdscxx: [ + { + title: '数据', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu', + source: ['/nyb/pc/messageView.jsp'], + target: (document) => { + if (!document) { + return '/gov/moa/zdscxx'; + } + const selected = document.querySelectorAll('.colorRed'); + const categories = Array.from(selected) + .map((s) => s.getAttribute('_key')) + .join('/'); + + return `/gov/moa/zdscxx${categories ? `/${categories}` : ''}`; + }, + }, + ], + }, 'moe.gov.cn': { _name: '中华人民共和国教育部', '.': [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index ebd1258ec..98d2cc4bd 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -21,6 +21,9 @@ module.exports = function (router) { router.get('/miit/zcwj', require('./miit/zcwj')); router.get('/miit/wjgs', require('./miit/wjgs')); router.get('/miit/zcjd', require('./miit/zcjd')); + router.get('/moa/sjzxfb/:category*', require('./moa/zdscxx')); + router.get('/moa/zdscxx/:category*', require('./moa/zdscxx')); + router.get('/moa/:suburl(.*)', require('./moa/moa')); router.get('/moe/:type', require('./moe/moe')); router.get('/moe/s78/:column', require('./moe/s78')); router.get('/mofcom/article/:suffix+', require('./mofcom/article')); diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index 4133a8ce7..2ff76eb15 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -1808,9 +1808,39 @@ Language -### 数据 - 最新发布 {#zhong-hua-ren-min-gong-he-guo-nong-ye-nong-cun-bu-shu-ju-zui-xin-fa-bu} +### 数据 {#zhong-hua-ren-min-gong-he-guo-nong-ye-nong-cun-bu-shu-ju} - + + +#### 报告主题 {#zhong-hua-ren-min-gong-he-guo-nong-ye-nong-cun-bu-shu-ju-bao-gao-zhu-ti} + +| 价格指数 | 供需月报 | 日历信息 | 蔬菜生产 | +| -------- | -------- | -------- | -------- | + +#### 报告来源 {#zhong-hua-ren-min-gong-he-guo-nong-ye-nong-cun-bu-shu-ju-bao-gao-lai-yuan} + +| 农业农村部市场与信息化司 | 农业农村部畜牧兽医局 | 农业农村部种植业管理司 | 农业农村部信息中心 | 农业农村部农业贸易促进中心 | +| ------------------------ | -------------------- | ---------------------- | ------------------ | -------------------------- | + +| 新华网 | 新闻晨报 | 楚天都市报 | 中国兴农网 | 泉州晚报 | +| ------ | -------- | ---------- | ---------- | -------- | + +| 潇湘晨报 | 澎湃新闻 | 环京津网 | 经济日报 | 腾讯网 | +| -------- | -------- | -------- | -------- | ------ | + +| 贵阳晚报 | 山东广播电视台闪电新闻客户端 | 央视网 | 农产品;平衡表;供需分析 | 农民日报 | +| -------- | ---------------------------- | ------ | ---------------------- | -------- | + +| 重庆市黔江区人民政府 | 农业农村部新闻办公室 | 农业农村部市场预警专家委员会 | 农业农村部市场畜牧兽医局 | 其它来源 | +| -------------------- | -------------------- | ---------------------------- | ------------------------ | -------- | + +| 人民网 | 人民日报 | 中央气象台 | 中国证券报 | 中国网 | +| ------ | -------- | ---------- | ---------- | ------ | + +| 中国新闻网 | 南方日报 | 黑龙江省政府新闻办 | +| ---------- | -------- | ------------------ | + + ## 中华人民共和国人力资源和社会保障部 {#zhong-hua-ren-min-gong-he-guo-ren-li-zi-yuan-he-she-hui-bao-zhang-bu}