feat(route): add 中华人民共和国农业农村部数据 (#13828)

This commit is contained in:
Ethan Shen 2023-11-20 20:18:50 +08:00 committed by GitHub
parent c6f700b4c8
commit bdc4b2bfbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 172 additions and 24 deletions

View File

@ -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'));

View File

@ -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),
})),
};
};

View File

@ -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'],

104
lib/v2/gov/moa/zdscxx.js Normal file
View File

@ -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,
};
};

View File

@ -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: '中华人民共和国教育部',
'.': [

View File

@ -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'));

View File

@ -1808,9 +1808,39 @@ Language
</Route>
### 数据 - 最新发布 {#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}
<Route author="MisteryMonster" example="/gov/moa/sjzxfb" path="/gov/moa/sjzxfb"/>
<Route author="MisteryMonster nczitzk" example="/gov/moa/zdscxx" path="/gov/moa/zdscxx/:channel?/:source?" paramsDesc={['报告主题,见下表,默认为全部', '报告来源,见下表,默认为全部']} radar="1" rssbud="1">
#### 报告主题 {#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}
| 农业农村部市场与信息化司 | 农业农村部畜牧兽医局 | 农业农村部种植业管理司 | 农业农村部信息中心 | 农业农村部农业贸易促进中心 |
| ------------------------ | -------------------- | ---------------------- | ------------------ | -------------------------- |
| 新华网 | 新闻晨报 | 楚天都市报 | 中国兴农网 | 泉州晚报 |
| ------ | -------- | ---------- | ---------- | -------- |
| 潇湘晨报 | 澎湃新闻 | 环京津网 | 经济日报 | 腾讯网 |
| -------- | -------- | -------- | -------- | ------ |
| 贵阳晚报 | 山东广播电视台闪电新闻客户端 | 央视网 | 农产品;平衡表;供需分析 | 农民日报 |
| -------- | ---------------------------- | ------ | ---------------------- | -------- |
| 重庆市黔江区人民政府 | 农业农村部新闻办公室 | 农业农村部市场预警专家委员会 | 农业农村部市场畜牧兽医局 | 其它来源 |
| -------------------- | -------------------- | ---------------------------- | ------------------------ | -------- |
| 人民网 | 人民日报 | 中央气象台 | 中国证券报 | 中国网 |
| ------ | -------- | ---------- | ---------- | ------ |
| 中国新闻网 | 南方日报 | 黑龙江省政府新闻办 |
| ---------- | -------- | ------------------ |
</Route>
## 中华人民共和国人力资源和社会保障部 {#zhong-hua-ren-min-gong-he-guo-ren-li-zi-yuan-he-she-hui-bao-zhang-bu}