From 3b53c4430e01cb250aae94e0cc7953c546dd7be3 Mon Sep 17 00:00:00 2001
From: Fatpandac <1779196284@qq.com>
Date: Sat, 5 Mar 2022 23:22:46 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=B7=A5=E4=B8=9A?=
=?UTF-8?q?=E5=92=8C=E4=BF=A1=E6=81=AF=E5=8C=96=E9=83=A8=20(#9221)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 工业和信息化部
* fix(route): change route path, docs and refactor to V2
---
docs/government.md | 8 ++++
lib/router.js | 5 ---
lib/v2/gov/maintainer.js | 5 +++
lib/v2/gov/miit/wjfb.js | 61 +++++++++++++++++++++++++++++
lib/{routes => v2}/gov/miit/wjgs.js | 0
lib/v2/gov/miit/yjzj.js | 59 ++++++++++++++++++++++++++++
lib/{routes => v2}/gov/miit/zcjd.js | 0
lib/{routes => v2}/gov/miit/zcwj.js | 0
lib/v2/gov/radar.js | 17 ++++++++
lib/v2/gov/router.js | 5 +++
10 files changed, 155 insertions(+), 5 deletions(-)
create mode 100644 lib/v2/gov/miit/wjfb.js
rename lib/{routes => v2}/gov/miit/wjgs.js (100%)
create mode 100644 lib/v2/gov/miit/yjzj.js
rename lib/{routes => v2}/gov/miit/zcjd.js (100%)
rename lib/{routes => v2}/gov/miit/zcwj.js (100%)
diff --git a/docs/government.md b/docs/government.md
index bf95b5dbdb..b91586f8ea 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -498,6 +498,14 @@ pageClass: routes
+### 文件发布
+
+
+
+### 意见征集
+
+
+
### 文件公示
diff --git a/lib/router.js b/lib/router.js
index 9c38be7607..7f1b646e8f 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2294,11 +2294,6 @@ router.get('/noi/winners-list', lazyloadRouteHandler('./routes/noi/winners-list'
router.get('/noi/province-news', lazyloadRouteHandler('./routes/noi/province-news'));
router.get('/noi/rg-news', lazyloadRouteHandler('./routes/noi/rg-news'));
-// 中国工业化和信息部
-router.get('/gov/miit/zcwj', lazyloadRouteHandler('./routes/gov/miit/zcwj'));
-router.get('/gov/miit/wjgs', lazyloadRouteHandler('./routes/gov/miit/wjgs'));
-router.get('/gov/miit/zcjd', lazyloadRouteHandler('./routes/gov/miit/zcjd'));
-
// 中国国家认证认可监管管理员会
router.get('/gov/cnca/jgdt', lazyloadRouteHandler('./routes/gov/cnca/jgdt'));
router.get('/gov/cnca/hydt', lazyloadRouteHandler('./routes/gov/cnca/hydt'));
diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js
index 7c09586eb0..fca5406178 100644
--- a/lib/v2/gov/maintainer.js
+++ b/lib/v2/gov/maintainer.js
@@ -7,4 +7,9 @@ module.exports = {
'/guangdong/tqyb/sncsyjxh': ['Fatpandac'],
'/huizhou/zwgk/:category?': ['Fatpandac'],
'/sichuan/deyang/govpulicinfo/:countyName/:institutionName?': ['zytomorrow'],
+ '/miit/wjfb/:ministry': ['Fatpandac'],
+ '/miit/yjzj': ['Fatpandac'],
+ '/miit/zcwj': ['Yoge-Code'],
+ '/miit/wjgs': ['Yoge-Code'],
+ '/miit/zcjd': ['Yoge-Code'],
};
diff --git a/lib/v2/gov/miit/wjfb.js b/lib/v2/gov/miit/wjfb.js
new file mode 100644
index 0000000000..d38dcc87bd
--- /dev/null
+++ b/lib/v2/gov/miit/wjfb.js
@@ -0,0 +1,61 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+
+const rootUrl = 'https://www.miit.gov.cn';
+
+module.exports = async (ctx) => {
+ const ministry = ctx.params.ministry;
+ const url = `${rootUrl}/jgsj/${ministry}/wjfb/index.html`;
+
+ const cookieResponse = await got(url);
+ const cookie = cookieResponse.headers['set-cookie'][0].split(';')[0];
+ const indexContent = cheerio.load(cookieResponse.data);
+ const title = indexContent('div.dqwz > a:nth-child(4)').text();
+ const dataRequestUrl = indexContent('div.lmy_main_rb > script:nth-child(2)')
+ .map((_, item) => ({
+ url: `${rootUrl}${indexContent(item).attr('url')}`,
+ queryData: JSON.parse(indexContent(item).attr('querydata').replace(/"/g, '|').replace(/'/g, '"').replace(/\|/g, '"')),
+ }))
+ .get()[0];
+
+ const dataUrl = `${dataRequestUrl.url}?${Object.keys(dataRequestUrl.queryData)
+ .map((key) => `${key}=${dataRequestUrl.queryData[key]}`)
+ .join('&')}`;
+ const response = await got({
+ method: 'get',
+ url: dataUrl,
+ headers: {
+ Cookie: cookie,
+ },
+ });
+ const $ = cheerio.load(response.data.data.html);
+ const list = $('ul > li')
+ .map((_, item) => ({
+ title: $(item).find('a').text(),
+ link: new URL($(item).find('a').attr('href'), rootUrl).href,
+ pubDate: parseDate($(item).find('span').text(), 'YYYY-MM-DD'),
+ }))
+ .get();
+
+ const items = await Promise.all(
+ list.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got(item.link);
+ const content = cheerio.load(detailResponse.data);
+
+ item.description = content('#con_con')
+ .html()
+ .replace(/()/g, '$1' + rootUrl + '$2' + '$3');
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: `工业和信息化部 - ${title} 文件发布`,
+ link: url,
+ item: items,
+ };
+};
diff --git a/lib/routes/gov/miit/wjgs.js b/lib/v2/gov/miit/wjgs.js
similarity index 100%
rename from lib/routes/gov/miit/wjgs.js
rename to lib/v2/gov/miit/wjgs.js
diff --git a/lib/v2/gov/miit/yjzj.js b/lib/v2/gov/miit/yjzj.js
new file mode 100644
index 0000000000..b6ad715373
--- /dev/null
+++ b/lib/v2/gov/miit/yjzj.js
@@ -0,0 +1,59 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+
+const rootUrl = 'https://www.miit.gov.cn';
+
+module.exports = async (ctx) => {
+ const url = `${rootUrl}/gzcy/yjzj/index.html`;
+
+ const cookieResponse = await got(url);
+ const cookie = cookieResponse.headers['set-cookie'][0].split(';')[0];
+ const indexContent = cheerio.load(cookieResponse.data);
+ const dataRequestUrl = indexContent('div.clist_con > script:nth-child(2)')
+ .map((_, item) => ({
+ url: `${rootUrl}${indexContent(item).attr('url')}`,
+ queryData: JSON.parse(indexContent(item).attr('querydata').replace(/"/g, '|').replace(/'/g, '"').replace(/\|/g, '"')),
+ }))
+ .get()[0];
+
+ const dataUrl = `${dataRequestUrl.url}?${Object.keys(dataRequestUrl.queryData)
+ .map((key) => `${key}=${dataRequestUrl.queryData[key]}`)
+ .join('&')}`;
+ const response = await got({
+ method: 'get',
+ url: dataUrl,
+ headers: {
+ Cookie: cookie,
+ },
+ });
+ const $ = cheerio.load(response.data.data.html);
+ const list = $('ul > li')
+ .map((_, item) => ({
+ title: $(item).find('a').text(),
+ link: new URL($(item).find('a').attr('href'), rootUrl).href,
+ pubDate: parseDate($(item).find('span').text(), 'YYYY-MM-DD'),
+ }))
+ .get();
+
+ const items = await Promise.all(
+ list.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got(item.link);
+ const content = cheerio.load(detailResponse.data);
+
+ item.description = content('#con_con')
+ .html()
+ .replace(/()/g, '$1' + rootUrl + '$2' + '$3');
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: `工业和信息化部 - 意见征集`,
+ link: url,
+ item: items,
+ };
+};
diff --git a/lib/routes/gov/miit/zcjd.js b/lib/v2/gov/miit/zcjd.js
similarity index 100%
rename from lib/routes/gov/miit/zcjd.js
rename to lib/v2/gov/miit/zcjd.js
diff --git a/lib/routes/gov/miit/zcwj.js b/lib/v2/gov/miit/zcwj.js
similarity index 100%
rename from lib/routes/gov/miit/zcwj.js
rename to lib/v2/gov/miit/zcwj.js
diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js
index fd778aa54e..96e074e0a6 100644
--- a/lib/v2/gov/radar.js
+++ b/lib/v2/gov/radar.js
@@ -376,4 +376,21 @@ module.exports = {
},
],
},
+ 'miit.gov.cn': {
+ _name: '工业和信息化部',
+ '.': [
+ {
+ title: '部门 文件发布',
+ docs: 'https://docs.rsshub.app/government.html#zhong-guo-gong-ye-he-xin-xi-hua-bu',
+ source: ['/jgsj/:ministry/wjfb/index.html'],
+ target: '/miit/wjfb/:ministry',
+ },
+ {
+ title: '征集意见',
+ docs: 'https://docs.rsshub.app/government.html#zhong-guo-gong-ye-he-xin-xi-hua-bu',
+ source: ['/gzcy/yjzj/index.html'],
+ target: '/miit/yjzj',
+ },
+ ],
+ },
};
diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js
index 892355701e..550ecffe1c 100644
--- a/lib/v2/gov/router.js
+++ b/lib/v2/gov/router.js
@@ -8,4 +8,9 @@ module.exports = function (router) {
router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh'));
router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index'));
router.get('/sichuan/deyang/govpulicinfo/:countyName/:institutionName?', require('./sichuan/deyang/govpulicinfo'));
+ router.get('/miit/wjfb/:ministry', require('./miit/wjfb'));
+ router.get('/miit/yjzj', require('./miit/yjzj'));
+ router.get('/miit/zcwj', require('./miit/zcwj'));
+ router.get('/miit/wjgs', require('./miit/wjgs'));
+ router.get('/miit/zcjd', require('./miit/zcjd'));
};