From 159da9059e9c726534b0bb944e024ccee4055cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E8=80=81=E9=A9=AC?= <119333994@qq.com> Date: Sat, 23 Apr 2022 02:21:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E6=95=99=E8=82=B2=E9=83=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=96=B0=E5=A2=9E=E6=95=99=E8=82=B2=E8=A6=81?= =?UTF-8?q?=E9=97=BB=E5=88=86=E7=B1=BB=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=96=87=E7=AB=A0=E6=A0=87=E9=A2=98=E5=8F=96=E5=80=BC?= =?UTF-8?q?=EF=BC=9B=E4=BC=98=E5=8C=96=E9=9B=AA=E7=90=83=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E4=BA=8E=E8=AE=A8=E8=AE=BA=E5=B8=96=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=8E=B7=E5=8F=96=E5=AE=8C=E6=95=B4=E5=86=85=E5=AE=B9?= =?UTF-8?q?=20(#9556)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 雪球的讨论帖可以直接从text字段中取到完整内容,长文帖只有description字段有值,获取逻辑不变 * 教育部路由增加“教育要闻”栏目类型获取,同时修复教育部文章title获取不到的问题 * 补充教育部路由增加教育要闻栏目类型的文档 * refactor: migrate to v2 * fix: legacy url.resolve * 修复雪球返回完整讨论帖时遗漏了转发内容的问题 * 移除重复的key Co-authored-by: TonyRL --- docs/government.md | 6 +++--- lib/router.js | 4 ++-- lib/v2/gov/maintainer.js | 25 ++++++++++++++----------- lib/{routes => v2}/gov/moe/moe.js | 21 +++++++-------------- lib/v2/gov/radar.js | 11 +++++++++++ lib/v2/gov/router.js | 27 +++++++++++++++------------ lib/v2/xueqiu/user.js | 5 +++-- 7 files changed, 55 insertions(+), 44 deletions(-) rename lib/{routes => v2}/gov/moe/moe.js (78%) diff --git a/docs/government.md b/docs/government.md index 84d427710..145d55170 100644 --- a/docs/government.md +++ b/docs/government.md @@ -933,9 +933,9 @@ pageClass: routes -| 政策解读 | 最新文件 | 公告公示 | 教育部简报 | -| :---------: | :---------: | :----: | :---------------: | -| policy_anal | newest_file | notice | edu_ministry_news | +| 政策解读 | 最新文件 | 公告公示 | 教育部简报 | 教育要闻 | +| :---------: | :---------: | :----: | :---------------: | :---------------: | +| policy_anal | newest_file | notice | edu_ministry_news | edu_focus_news | diff --git a/lib/router.js b/lib/router.js index 40a058a1d..ee9296538 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1220,8 +1220,8 @@ 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/moe/:type', lazyloadRouteHandler('./routes/gov/moe/moe')); +// 中华人民共和国教育部 migrated to v2 +// router.get('/gov/moe/:type', lazyloadRouteHandler('./routes/gov/moe/moe')); // 中华人民共和国外交部 // router.get('/gov/fmprc/fyrbt', lazyloadRouteHandler('./routes/gov/fmprc/fyrbt')); diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index c17a95579..d9c55dae1 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -1,24 +1,27 @@ module.exports = { - '/anhui/kjt/:path?': ['nczitzk'], - '/beijing/kw/:channel': ['Fatpandac'], - '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], - '/shenzhen/zzb/:caty/:page?': ['zlasd'], - '/shanghai/rsj/ksxm': ['Fatpandac'], '/fmprc/:category?': ['nicolaszf', 'nczitzk'], - '/guangdong/tqyb/tfxtq': ['Fatpandac'], - '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], - '/huizhou/zwgk/:category?': ['Fatpandac'], - '/sichuan/deyang/govpulicinfo/:countyName': ['zytomorrow'], + '/mee/ywdt?': ['liuxsdev'], '/mfa/wjdt/:category?': ['nczitzk'], '/miit/wjfb/:ministry': ['Fatpandac'], '/miit/yjzj': ['Fatpandac'], '/miit/zcwj': ['Yoge-Code'], '/miit/wjgs': ['Yoge-Code'], '/miit/zcjd': ['Yoge-Code'], - '/mee/ywdt?': ['liuxsdev'], + '/moe/:type': ['Crawler995'], '/nrta/news/:category?': ['yuxinliu-alex'], '/pbc/goutongjiaoliu': ['nczitzk'], + '/pbc/gzlw': ['Fatpandac'], '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], - '/pbc/gzlw': ['Fatpandac'], + + '/anhui/kjt/:path?': ['nczitzk'], + '/beijing/kw/:channel': ['Fatpandac'], + '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], + '/shenzhen/zzb/:caty/:page?': ['zlasd'], + '/shanghai/rsj/ksxm': ['Fatpandac'], + '/shanghai/wsjkw/yqtb': ['zcf0508'], + '/guangdong/tqyb/tfxtq': ['Fatpandac'], + '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], + '/huizhou/zwgk/:category?': ['Fatpandac'], + '/sichuan/deyang/govpulicinfo/:countyName': ['zytomorrow'], }; diff --git a/lib/routes/gov/moe/moe.js b/lib/v2/gov/moe/moe.js similarity index 78% rename from lib/routes/gov/moe/moe.js rename to lib/v2/gov/moe/moe.js index 5c6be04e1..9ac5a073b 100644 --- a/lib/routes/gov/moe/moe.js +++ b/lib/v2/gov/moe/moe.js @@ -1,7 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const logger = require('@/utils/logger'); -const liburl = require('url'); +const { parseDate } = require('@/utils/parse-date'); const moeUrl = 'http://www.moe.gov.cn/'; const typesIdMap = [ @@ -9,6 +9,7 @@ const typesIdMap = [ { type: 'newest_file', id: 'nine_con1', name: '最新文件' }, { type: 'notice', id: 'nine_con2', name: '公告公示' }, { type: 'edu_ministry_news', id: 'nine_con3', name: '教育部简报' }, + { type: 'edu_focus_news', id: 'eight_con2 .TRS_Editor', name: '教育要闻' }, ]; module.exports = async (ctx) => { @@ -28,11 +29,7 @@ module.exports = async (ctx) => { return; } - const response = await got({ - method: 'get', - url: moeUrl, - Host: 'www.moe.gov.cn', - }); + const response = await got(moeUrl); const $ = cheerio.load(response.data); const newsLis = $('div#' + id + '>ul>li'); @@ -46,15 +43,11 @@ module.exports = async (ctx) => { item = $(item); const firstA = item.find('a'); - const itemUrl = liburl.resolve(moeUrl, firstA.attr('href')); + const itemUrl = new URL(firstA.attr('href'), moeUrl).href; const infos = await ctx.cache.tryGet(itemUrl, async () => { const res = {}; - const response = await got({ - method: 'get', - url: itemUrl, - Host: 'www.moe.gov.cn', - }); + const response = await got(itemUrl); const data = cheerio.load(response.data); if (itemUrl.indexOf('www.gov.cn') > -1) { @@ -65,7 +58,7 @@ module.exports = async (ctx) => { res.title = data('div#xxgk_content_redheadbg > h1').text(); } else if (itemUrl.indexOf('jyb_') > -1) { res.description = data('div.TRS_Editor').html(); - res.title = data('div#content_body > h1').text(); + res.title = data('div.TRS_Editor').siblings('h1').first().text(); } return res; @@ -75,7 +68,7 @@ module.exports = async (ctx) => { title: infos.title, description: infos.description, link: itemUrl, - pubDate: `${new Date().getFullYear()}-${item.find('span').text()}`, + pubDate: parseDate(item.find('span').text(), 'MM-DD'), }; }) .get() diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index f78969e7e..af92edb2c 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -374,6 +374,17 @@ module.exports = { }, ], }, + 'moe.gov.cn': { + _name: '中华人民共和国教育部', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/government.html#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu', + source: ['/'], + target: '/gov/moe/newest_file', + }, + ], + }, 'nrta.gov.cn': { _name: '国家广播电视总局', '.': [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 6dd0d04f5..fc7ec613a 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -1,25 +1,28 @@ module.exports = function (router) { - router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt')); - router.get('/beijing/kw/:channel', require('./beijing/kw/index')); - router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index')); - router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); - router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm')); - router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb')); + // ministry router.get('/fmprc/:category?', require('./mfa/wjdt')); - router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq')); - router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh')); - router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index')); - router.get('/sichuan/deyang/govpulicinfo/:countyName', require('./sichuan/deyang/govpulicinfo')); + router.get('/mee/ywdt/:category?', require('./mee/ywdt')); router.get('/mfa/wjdt/:category?', require('./mfa/wjdt')); 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')); - router.get('/mee/ywdt/:category?', require('./mee/ywdt')); + router.get('/moe/:type', require('./moe/moe')); router.get('/nrta/news/:category?', require('./nrta/news')); router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu')); - router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement')); router.get('/pbc/gzlw', require('./pbc/gzlw')); + router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement')); router.get('/pbc/zcyj', require('./pbc/zcyj')); + // province + router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt')); + router.get('/beijing/kw/:channel', require('./beijing/kw/index')); + router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index')); + router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); + router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm')); + router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb')); + router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq')); + router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh')); + router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index')); + router.get('/sichuan/deyang/govpulicinfo/:countyName', require('./sichuan/deyang/govpulicinfo')); }; diff --git a/lib/v2/xueqiu/user.js b/lib/v2/xueqiu/user.js index cbff540c8..7e0bc83cf 100644 --- a/lib/v2/xueqiu/user.js +++ b/lib/v2/xueqiu/user.js @@ -41,10 +41,11 @@ module.exports = async (ctx) => { link: `https://xueqiu.com/u/${id}`, description: `${data[0].user.screen_name} 的雪球${typename[type]}动态`, item: data.map((item) => { - const description = item.description + (item.retweeted_status ? `
${item.retweeted_status.user.screen_name}: ${item.retweeted_status.description}
` : ''); + const retweetedStatus = item.retweeted_status ? `
${item.retweeted_status.user.screen_name}: ${item.retweeted_status.description}
` : ''; + const description = item.description + retweetedStatus; return { title: item.title ? item.title : description.replace(/<[^>]+>/g, ''), - description, + description: item.text ? (item.text + retweetedStatus) : description, pubDate: parseDate(item.created_at), link: `https://xueqiu.com${item.target}`, };