Skip to content

Commit

Permalink
Merge pull request #2242 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Nov 21, 2023
2 parents a07e3ba + 1765c55 commit 1c1c8d4
Show file tree
Hide file tree
Showing 20 changed files with 543 additions and 205 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
20 changes: 0 additions & 20 deletions lib/routes/gov/moa/sjzxfb.js

This file was deleted.

5 changes: 4 additions & 1 deletion lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -51,7 +53,8 @@ module.exports = {
'/zhengce/govall/:advance?': ['ciaranchen'],
'/zhengce/wenjian/:pcodeJiguan?': ['ciaranchen'],
'/zhengce/zhengceku/:department': ['zxx-457'],
'/zhengce/zuixin': ['SettingDust'],
'/zhengce/zuixin': ['SettingDust', 'nczitzk'],
'/zhengce/:category?': ['nczitzk'],
// province
'/anhui/kjt/:path?': ['nczitzk'],
'/beijing/bphc/:channel': ['bigfei'],
Expand Down
File renamed without changes.
104 changes: 104 additions & 0 deletions lib/v2/gov/moa/zdscxx.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
39 changes: 39 additions & 0 deletions lib/v2/gov/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: (_params, _url, 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: '中华人民共和国教育部',
'.': [
Expand Down Expand Up @@ -1194,6 +1223,16 @@ module.exports = {
source: ['/pushinfo/v150203', '/'],
target: '/gov/news/gwy',
},
{
title: '政策',
docs: 'https://docs.rsshub.app/routes/government#zhong-guo-zheng-fu-wang-zheng-ce',
source: ['/zhengce/:category*'],
target: (params) => {
const category = params.category;

return `/gov/zhengce${category ? `/${category}` : ''}`;
},
},
{
title: '最新政策',
docs: 'https://docs.rsshub.app/routes/government#zhong-guo-zheng-fu-wang',
Expand Down
6 changes: 5 additions & 1 deletion lib/v2/gov/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -43,7 +46,8 @@ module.exports = function (router) {
router.get('/zhengce/govall/:advance?', require('./zhengce/govall'));
router.get('/zhengce/wenjian/:pcodeJiguan?', require('./zhengce/wenjian'));
router.get('/zhengce/zhengceku/:department', require('./zhengce/zhengceku'));
router.get('/zhengce/zuixin', require('./zhengce/zuixin'));
router.get('/zhengce/zuixin', require('./zhengce'));
router.get('/zhengce/:category*', require('./zhengce'));
// province
router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt'));
router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc'));
Expand Down
99 changes: 99 additions & 0 deletions lib/v2/gov/zhengce/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { category = 'zuixin' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const rootUrl = 'https://www.gov.cn';
const currentUrl = new URL(`zhengce/${category.replace(/\/$/, '')}/`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('h4 a, div.subtitle a[title]')
.toArray()
.map((item) => {
item = $(item);

const link = item.prop('href');

return {
title: item.text(),
link: link.startsWith('http') ? link : new URL(link, currentUrl).href,
};
});

items = await Promise.all(
items
.filter((item) => /https?:\/\/www\.gov\.cn\/zhengce.*content_\d+\.htm/.test(item.link))
.slice(0, limit)
.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

const processElementText = (el) => content(el).text().split(//).pop().trim() || content(el).next().text().trim();

const author = content('meta[name="author"]').prop('content');

const agencyEl = content('table.bd1')
.find('td')
.toArray()
.filter((a) => content(a).text().startsWith('发文机关'))
.pop();

const sourceEl = content('span.font-zyygwj')
.toArray()
.filter((a) => content(a).text().startsWith('来源'))
.pop();

const subjectEl = content('table.bd1')
.find('td')
.toArray()
.filter((a) => content(a).text().startsWith('主题分类'))
.pop();

const agency = agencyEl ? processElementText(agencyEl) : undefined;
const source = sourceEl ? processElementText(sourceEl) : undefined;
const subject = subjectEl ? processElementText(subjectEl) : content('td.zcwj_ztfl').text();

const column = content('meta[name="lanmu"]').prop('content');
const keywords = content('meta[name="keywords"]').prop('content')?.split(/;|,/) ?? [];
const manuscriptId = content('meta[name="manuscriptId"]').prop('content');

item.title = content('div.share-title').text() || item.title;
item.description = content('div.TRS_UEDITOR').first().html() || content('div#UCAP-CONTENT, td#UCAP-CONTENT').first().html();
item.author = [agency, source, author].filter((a) => a).join('/');
item.category = [...new Set([subject, column, ...keywords].filter((c) => c))];
item.guid = `gov-zhengce-${manuscriptId}`;
item.pubDate = timezone(parseDate(content('meta[name="firstpublishedtime"]').prop('content'), 'YYYY-MM-DD-HH:mm:ss'), +8);
item.updated = timezone(parseDate(content('meta[name="lastmodifiedtime"]').prop('content'), 'YYYY-MM-DD-HH:mm:ss'), +8);

return item;
})
)
);

const image = new URL($('img.wordlogo').prop('src'), rootUrl).href;
const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href;
const subtitle = $('meta[name="lanmu"]').prop('content');
const author = $('div.header_logo a[aria-label]').prop('aria-label');

ctx.state.data = {
item: items,
title: author && subtitle ? `${author} - ${subtitle}` : $('title').text(),
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh-CN',
image,
icon,
logo: icon,
subtitle,
author,
};
};
39 changes: 0 additions & 39 deletions lib/v2/gov/zhengce/zuixin.js

This file was deleted.

Loading

0 comments on commit 1c1c8d4

Please sign in to comment.