feat(route): add 中华人民共和国农业农村部生猪专题重要政策 (#16961)
This commit is contained in:
parent
4b128aca9d
commit
2bc358296e
|
|
@ -8,13 +8,13 @@ const hostUrl = 'http://www.moa.gov.cn/';
|
|||
const hostUrlObj = new URL(hostUrl); // 用于在下面判断 host
|
||||
|
||||
export const route: Route = {
|
||||
path: '/moa/:suburl{.+}',
|
||||
path: '/moa/suburl/:suburl{.+}',
|
||||
categories: ['government'],
|
||||
example: '/gov/moa/gk/zcjd/',
|
||||
example: '/gov/moa/suburl/gk/zcjd/',
|
||||
radar: [
|
||||
{
|
||||
source: ['moa.gov.cn/'],
|
||||
target: '/moa/:suburl',
|
||||
target: '/moa/suburl/:suburl',
|
||||
},
|
||||
],
|
||||
parameters: { suburl: '下级目录,请使用最下级的目录' },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
import { Route } from '@/types';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const handler = async (ctx) => {
|
||||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 6;
|
||||
|
||||
const rootUrl = 'http://www.moa.gov.cn';
|
||||
const currentUrl = new URL(`ztzl/szcpxx/zyzc/index.htm`, rootUrl).href;
|
||||
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = load(response);
|
||||
|
||||
const language = $('html').prop('lang');
|
||||
|
||||
let items = $('div.ztst_list_contBox_inner ul li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a.content');
|
||||
|
||||
return {
|
||||
title: a.prop('title'),
|
||||
pubDate: parseDate(item.find('div.pubTime').text().split(/:/).pop(), 'YYYY.MM.DD'),
|
||||
link: new URL(a.prop('href'), currentUrl).href,
|
||||
language,
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const $$ = load(detailResponse);
|
||||
|
||||
const title = $$('h2.xxgk_title, h1.bjjMTitle').text();
|
||||
const description = $$('div.gsj_htmlcon_bot, div.TRS_Editor').html();
|
||||
const guid = `moa-${$$('meta[name="contentid"]').prop('content')}`;
|
||||
|
||||
item.title = title;
|
||||
item.description = description;
|
||||
item.pubDate = timezone(parseDate($$('meta[name="PubDate"]').prop('content')), +8);
|
||||
item.category = [
|
||||
...new Set([
|
||||
$$('meta[name="SiteName"]').prop('content'),
|
||||
$$('meta[name="ColumnName"]').prop('content'),
|
||||
$$('meta[name="ColumnType"]').prop('content'),
|
||||
$$('meta[name="ContentSource"]').prop('content'),
|
||||
$$('meta[name="Keywords"]').prop('content'),
|
||||
]),
|
||||
].filter(Boolean);
|
||||
item.author = $$('meta[name="Author"]').prop('content') || $$('meta[name="source"]').prop('content');
|
||||
item.guid = guid;
|
||||
item.id = guid;
|
||||
item.content = {
|
||||
html: description,
|
||||
text: $$('div.gsj_htmlcon_bot, div.TRS_Editor').text(),
|
||||
};
|
||||
item.language = language;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const title = `${$('title').text()} - ${$('li.now').text()}`;
|
||||
const image = new URL($('img.leftLogo').prop('src'), currentUrl).href;
|
||||
|
||||
return {
|
||||
title,
|
||||
description: title,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
allowEmpty: true,
|
||||
image,
|
||||
author: '中华人民共和国农业农村部',
|
||||
language,
|
||||
};
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/moa/szcpxx',
|
||||
name: '中华人民共和国农业农村部生猪专题重要政策',
|
||||
url: 'www.moa.gov.cn',
|
||||
maintainers: ['nczitzk'],
|
||||
handler,
|
||||
example: '/gov/moa/szcpxx',
|
||||
parameters: undefined,
|
||||
description: undefined,
|
||||
categories: ['government'],
|
||||
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportRadar: true,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['www.moa.gov.cn/ztzl/szcpxx/zyzc/index.htm'],
|
||||
target: '/moa/szcpxx',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
@ -1,18 +1,12 @@
|
|||
import { Route } from '@/types';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: ['/moa/sjzxfb/:category{.+}?', '/moa/zdscxx/:category{.+}?'],
|
||||
name: 'Unknown',
|
||||
maintainers: [],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const category = ctx.req.param('category');
|
||||
export const handler = async (ctx) => {
|
||||
const { category } = ctx.req.param();
|
||||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5;
|
||||
|
||||
const domain = 'moa.gov.cn';
|
||||
|
|
@ -36,7 +30,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
const filters = filterResponse.result.reduce((filters, f) => {
|
||||
filters[f.name] = f.data.map((d) => d.name);
|
||||
filters[f.name.trim()] = f.data.map((d) => d.name.trim());
|
||||
return filters;
|
||||
}, {});
|
||||
|
||||
|
|
@ -92,20 +86,76 @@ async function handler(ctx) {
|
|||
const $ = load(frameResponse);
|
||||
|
||||
const title = $('title').text();
|
||||
const description = '数据';
|
||||
const icon = new URL('favicon.ico', rootUrl).href;
|
||||
|
||||
return {
|
||||
item: items,
|
||||
title: `${title} - ${description} - ${category}`,
|
||||
title: `${title}${category ? ` - ${category}` : ''}`,
|
||||
description: '数据',
|
||||
link: currentUrl,
|
||||
description,
|
||||
language: 'zh',
|
||||
image: $('h1.logo a img').prop('src'),
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: category,
|
||||
author: title,
|
||||
item: items,
|
||||
allowEmpty: true,
|
||||
image: $('h1.logo a img').prop('src'),
|
||||
author: title,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/moa/zdscxx/:category{.+}?',
|
||||
name: '中华人民共和国农业农村部数据',
|
||||
url: 'www.moa.gov.cn',
|
||||
maintainers: ['nczitzk'],
|
||||
handler,
|
||||
example: '/gov/moa/zdscxx',
|
||||
parameters: { category: '分类,默认为全部,见下表' },
|
||||
description: `:::tip
|
||||
若订阅 [中华人民共和国农业农村部数据](http://zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp) 的 \`价格指数\` 报告主题。此时路由为 [\`/gov/moa/zdscxx/价格指数\`](https://rsshub.app/gov/moa/zdscxx/价格指数)。
|
||||
|
||||
若订阅 \`央视网\` 报告来源 的 \`蔬菜生产\` 报告主题。此时路由为 [\`/gov/moa/zdscxx/央视网/蔬菜生产\`](https://rsshub.app/gov/moa/zdscxx/央视网/蔬菜生产)。
|
||||
:::
|
||||
|
||||
| 价格指数 | 供需形势 | 分析报告周报 | 分析报告日报 | 日历信息 | 蔬菜生产 |
|
||||
| -------- | -------- | ------------ | ------------ | -------- | -------- |
|
||||
`,
|
||||
categories: ['government'],
|
||||
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportRadar: true,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
title: '价格指数',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/价格指数',
|
||||
},
|
||||
{
|
||||
title: '供需形势',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/供需形势',
|
||||
},
|
||||
{
|
||||
title: '分析报告周报',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/分析报告周报',
|
||||
},
|
||||
{
|
||||
title: '分析报告日报',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/分析报告日报',
|
||||
},
|
||||
{
|
||||
title: '日历信息',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/日历信息',
|
||||
},
|
||||
{
|
||||
title: '蔬菜生产',
|
||||
source: ['zdscxx.moa.gov.cn:8080/nyb/pc/messageList.jsp'],
|
||||
target: '/gov/moa/zdscxx/蔬菜生产',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue