From 007948efcd0caaa5b45202274e6ec1af057a89a3 Mon Sep 17 00:00:00 2001
From: liuxsdev <1028330144@qq.com>
Date: Tue, 8 Mar 2022 21:49:30 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20=E7=94=9F=E6=80=81=E7=8E=AF?=
=?UTF-8?q?=E5=A2=83=E9=83=A8-=E8=A6=81=E9=97=BB=E5=8A=A8=E6=80=81=20(#924?=
=?UTF-8?q?8)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): 生态环境部-要闻动态
---
docs/government.md | 8 +++-
lib/router.js | 3 --
lib/routes/gov/mee/gs.js | 54 ---------------------------
lib/v2/gov/maintainer.js | 1 +
lib/v2/gov/mee/ywdt.js | 80 ++++++++++++++++++++++++++++++++++++++++
lib/v2/gov/radar.js | 11 ++++++
lib/v2/gov/router.js | 1 +
7 files changed, 99 insertions(+), 59 deletions(-)
delete mode 100644 lib/routes/gov/mee/gs.js
create mode 100644 lib/v2/gov/mee/ywdt.js
diff --git a/docs/government.md b/docs/government.md
index 01c91342ed..d2f8bb5f17 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -952,9 +952,13 @@ pageClass: routes
## 中华人民共和国生态环境部
-### 公示
+### 要闻动态
-
+
+
+| 时政要闻 | 环境要闻 | 地方快讯 | 新闻发布 | 视频新闻 | 公示公告 |
+| :--: | :------: | :----: | :--: | :--: | :--: |
+| szyw | hjywnews | dfnews | xwfb | spxw | gsgg |
## 中华人民共和国退役军人事务部
diff --git a/lib/router.js b/lib/router.js
index d0c072bd9e..ec22d9b7af 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1262,9 +1262,6 @@ router.get('/gov/ndrc/xwdt/:caty?', lazyloadRouteHandler('./routes/gov/ndrc/xwdt
// 中华人民共和国-海关总署
router.get('/gov/customs/list/:gchannel', lazyloadRouteHandler('./routes/gov/customs/list'));
-// 中华人民共和国生态环境部
-router.get('/gov/mee/gs', lazyloadRouteHandler('./routes/gov/mee/gs'));
-
// 中华人民共和国教育部
router.get('/gov/moe/:type', lazyloadRouteHandler('./routes/gov/moe/moe'));
diff --git a/lib/routes/gov/mee/gs.js b/lib/routes/gov/mee/gs.js
deleted file mode 100644
index fcaee335bf..0000000000
--- a/lib/routes/gov/mee/gs.js
+++ /dev/null
@@ -1,54 +0,0 @@
-const got = require('@/utils/got');
-const cheerio = require('cheerio');
-
-module.exports = async (ctx) => {
- const linkBase = `http://www.mee.gov.cn/xxgk/gs/gsq/`;
- const listData = await got.get(linkBase);
- const $ = cheerio.load(listData.data);
- ctx.state.data = {
- title: `公示 - 中华人民共和国生态环境部`,
- link: linkBase,
- item: await Promise.all(
- $('.main .main_top li')
- .map(async (_, el) => {
- const $el = $(el);
- const $a = $el.find('>a');
- const href = $a.attr('href');
- const key = `gov_gs: ${href}`;
- let description;
- const value = await ctx.cache.get(key);
-
- // 移除 href 中的 ./,并且拼接原来的 url
- const link = `${linkBase}${href.slice(2)}`;
-
- if (value) {
- description = value;
- } else {
- const contentData = await got.get(link);
- const $content = cheerio.load(contentData.data);
- description = $content('.TRS_Editor').html();
- ctx.cache.set(key, description);
- }
-
- const title = $a.text();
-
- // 获取 date
- const pubDate = new Date(
- $el
- .find('.shover')
- .first()
- .text()
- .match(/\d{4}-\d{2}-\d{2}/)
- ).toUTCString();
-
- return {
- title,
- description,
- link,
- pubDate,
- };
- })
- .get()
- ),
- };
-};
diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js
index fca5406178..2dbd37212e 100644
--- a/lib/v2/gov/maintainer.js
+++ b/lib/v2/gov/maintainer.js
@@ -12,4 +12,5 @@ module.exports = {
'/miit/zcwj': ['Yoge-Code'],
'/miit/wjgs': ['Yoge-Code'],
'/miit/zcjd': ['Yoge-Code'],
+ '/mee/ywdt?': ['liuxsdev'],
};
diff --git a/lib/v2/gov/mee/ywdt.js b/lib/v2/gov/mee/ywdt.js
new file mode 100644
index 0000000000..b0e176926d
--- /dev/null
+++ b/lib/v2/gov/mee/ywdt.js
@@ -0,0 +1,80 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+const timezone = require('@/utils/timezone');
+
+const baseUrl = 'https://www.mee.gov.cn/';
+const columns = {
+ szyw: { name: '时政要闻', order: 1 },
+ hjywnews: { name: '环境要闻', order: 2 },
+ dfnews: { name: '地方快讯', order: 3 },
+ xwfb: { name: '新闻发布', order: 4 },
+ spxw: { name: '视频新闻', order: 5 },
+ gsgg: { name: '公示公告', order: 6 },
+};
+
+module.exports = async (ctx) => {
+ const cate = ctx.params.category ?? 'szyw';
+ const url = `${baseUrl}ywdt/`;
+ const title = `${columns[cate].name} - 要闻动态 - 中华人民共和国生态环境部`;
+ const response = await got(url);
+ const $ = cheerio.load(response.data);
+ const all = $('.bd');
+ const list = all
+ .find(`div:nth-child(${columns[cate].order})`)
+ .find('.mobile_none li , .mobile_clear li')
+ .map((_, item) => {
+ const title = $(item).find('a.cjcx_biaob').text().trim();
+ const href = $(item).find('a').attr('href');
+
+ let absolute_path;
+ if (href.search('\\./') === 0) {
+ absolute_path = `${url}${href.slice(2)}`;
+ } else if (href.search('\\./') === 1) {
+ absolute_path = `${baseUrl}${href.slice(3)}`;
+ } else {
+ absolute_path = href;
+ }
+ const link = absolute_path;
+ return {
+ title,
+ link,
+ };
+ })
+ .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);
+ try {
+ item.pubDate = timezone(parseDate(content('meta[name=PubDate]').attr('content')), +8);
+ // 视频新闻规则不一样
+ if (cate === 'spxw') {
+ item.title = content('meta[name=ArticleTitle]').attr('content');
+ // 取消视频自动播放
+ const video_control = content('.neiright_JPZ_GK_CP video');
+ video_control.removeAttr('autoplay');
+ // 视频路径转绝对路径
+ const video_source = content('.neiright_JPZ_GK_CP source');
+ const video_href = video_source.attr('src');
+ const _title_href = item.link.split('/').slice(-1)[0];
+ const _video_src = item.link.replace(_title_href, video_href.slice(2));
+ video_source.attr('src', _video_src);
+ }
+ item.description = content('.neiright_JPZ_GK_CP').html();
+ } catch (e) {
+ item.description = '';
+ }
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title,
+ link: url,
+ item: items,
+ };
+};
diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js
index 96e074e0a6..0d066e1f08 100644
--- a/lib/v2/gov/radar.js
+++ b/lib/v2/gov/radar.js
@@ -393,4 +393,15 @@ module.exports = {
},
],
},
+ 'mee.gov.cn': {
+ _name: '生态环境部',
+ www: [
+ {
+ title: '要闻动态',
+ docs: 'https://docs.rsshub.app/government.html#zhong-hua-ren-min-gong-he-guo-sheng-tai-huan-jing-bu',
+ source: ['/ywdt/:category'],
+ target: '/gov/mee/ywdt/:category',
+ },
+ ],
+ },
};
diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js
index 550ecffe1c..3812a52ed9 100644
--- a/lib/v2/gov/router.js
+++ b/lib/v2/gov/router.js
@@ -13,4 +13,5 @@ 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('/mee/ywdt/:category?', require('./mee/ywdt'));
};