diff --git a/docs/government.md b/docs/government.md index edd5a9edbd..7c23e5128d 100644 --- a/docs/government.md +++ b/docs/government.md @@ -127,6 +127,30 @@ pageClass: routes +## 国家药品审评网站 + +### 首页 + + + +- 频道 + +| 新闻中心 | 政策法规 | +| :------: | :------: | +| news | policy | + +- 类别 + +| 新闻中心 | 政务新闻 | 要闻导读 | 图片新闻 | 工作动态 | +| :------: | :------: | :------: | :------: | :------: | +| | zwxw | ywdd | tpxw | gzdt | + +| 政策法规 | 法律法规 | 中心规章 | +| :------: | :------: | :------: | +| | flfg | zxgz | + + + ## 哈尔滨市科技局 ### 政务公开 diff --git a/lib/v2/cde/index.js b/lib/v2/cde/index.js new file mode 100644 index 0000000000..bf6bd4cdb3 --- /dev/null +++ b/lib/v2/cde/index.js @@ -0,0 +1,132 @@ +const utils = require('./utils'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const channelLinkMap = { + news: 'https://www.cde.org.cn/main/news/listpage/545cf855a50574699b46b26bcb165f32', + policy: 'https://www.cde.org.cn/main/policy/listpage/9f9c74c73e0f8f56a8bfbc646055026d', +}; + +const cateUrlMap = { + news: { + zwxw: 'getList', + ywdd: 'getHotNewsList', + tpxw: 'getPictureNewsList', + gzdt: 'getWorkList', + }, + policy: { + flfg: 'getPolicyList', + zxgz: 'getRuleList', + }, +}; + +const cateTitleMap = { + news: { + zwxw: '政务新闻', + ywdd: '要闻导读', + tpxw: '图片新闻', + gzdt: '工作动态', + }, + policy: { + flfg: '法律法规', + zxgz: '政策规章', + }, +}; + +const requestData = { + news: { + zwxw: { + pageSize: 25, + pageNum: 1, + classId: '545cf855a50574699b46b26bcb165f32', + }, + ywdd: { + pageSize: 25, + pageNum: 1, + ishot: 1, + }, + tpxw: { + pageSize: 25, + pageNum: 1, + }, + gzdt: { + pageSize: 25, + pageNum: 1, + classId: '8dc6aac86eb083759b1e01615617a347', + }, + }, + policy: { + flfg: { + pageNum: 1, + pageSize: 25, + fclass: 0, + keyName: 'TITLE', + logicC: 'bh', + }, + zxgz: { + pageNum: 1, + pageSize: 25, + fclass: 0, + keyName: 'TITLE', + logicC: 'bh', + }, + }, +}; + +module.exports = async (ctx) => { + const channel = ctx.params.channel; + const cate = ctx.params.category; + requestData[channel][cate].pageSize = ctx.params.limit ?? 25; + + const url = `${utils.rootUrl}/main/${channel}/${cateUrlMap[channel][cate]}`; + const response = await got({ + method: 'post', + url, + headers: { + cookie: await utils.getCookie(ctx), + }, + form: requestData[channel][cate], + }); + const data = response.data.data; + const list = data.records.map((item) => { + const linkMap = { + news: `${utils.rootUrl}/main/${item.isPic ? 'newspic/view/' : 'news/viewInfoCommon/'}${item.newsIdCode}`, + policy: `${utils.rootUrl}/main/${item.regulatIdCODE ? `policy/regulatview/${item.regulatIdCODE}` : `policy/view/${item.policyIdCODE}`}`, + }; + + return { + title: item.title, + link: linkMap[channel], + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link, { + headers: { + cookie: await utils.getCookie(ctx), + }, + }); + const $ = cheerio.load(detailResponse.data); + + item.pubDate = parseDate($('div.news_detail_date').text(), 'YYYYMMDD'); + + const desc = $('div.news_detail_box'); + const removeTitle = desc.find('div.news_detail_title').remove().end(); + const removeDate = removeTitle.find('div.news_detail_date').remove().end(); + const removeImage = removeDate.find('img').remove().end(); + item.description = removeImage.html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${utils.title} - ${cateTitleMap[channel][cate]}`, + link: String(channelLinkMap[channel]), + item: items, + }; +}; diff --git a/lib/v2/cde/maintainer.js b/lib/v2/cde/maintainer.js new file mode 100644 index 0000000000..294d158154 --- /dev/null +++ b/lib/v2/cde/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:channel/:category': ['Fatpandac'], +}; diff --git a/lib/v2/cde/radar.js b/lib/v2/cde/radar.js new file mode 100644 index 0000000000..08d7a6eb8f --- /dev/null +++ b/lib/v2/cde/radar.js @@ -0,0 +1,43 @@ +module.exports = { + 'cde.org.cn': { + _name: '国家药品监督管理局药品审评中心', + www: [ + { + title: '政务新闻', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/news/listpage/545cf855a50574699b46b26bcb165f32'], + target: '/cde/news/zwxw', + }, + { + title: '要闻导读', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/news/listpage/545cf855a50574699b46b26bcb165f32'], + target: '/cde/news/ywdd', + }, + { + title: '图片新闻', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/news/listpage/545cf855a50574699b46b26bcb165f32'], + target: '/cde/news/tpxw', + }, + { + title: '工作动态', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/news/listpage/545cf855a50574699b46b26bcb165f32'], + target: '/cde/news/gzdt', + }, + { + title: '法律法规', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/policy/listpage/9f9c74c73e0f8f56a8bfbc646055026d'], + target: '/cde/policy/flfg', + }, + { + title: '中心规章', + docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-shen-ping-wang-zhan-shou-ye', + source: ['/main/policy/listpage/9f9c74c73e0f8f56a8bfbc646055026d'], + target: '/cde/policy/zxgz', + }, + ], + }, +}; diff --git a/lib/v2/cde/router.js b/lib/v2/cde/router.js new file mode 100644 index 0000000000..f487b5733d --- /dev/null +++ b/lib/v2/cde/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:channel/:category', require('./index')); +}; diff --git a/lib/v2/cde/utils.js b/lib/v2/cde/utils.js new file mode 100644 index 0000000000..cbe24866d0 --- /dev/null +++ b/lib/v2/cde/utils.js @@ -0,0 +1,20 @@ +const got = require('@/utils/got'); + +const title = '国家药品监督管理局药品审评中心'; +const rootUrl = 'https://www.cde.org.cn'; + +const getCookie = (ctx) => + ctx.cache.tryGet(rootUrl, async () => { + const response = await got.get(rootUrl); + + return response.headers['set-cookie'] + .join() + .match(/FSSBBIl1UgzbN7N80.*?;/g) + .join(''); + }); + +module.exports = { + title, + rootUrl, + getCookie, +};