From 3195eb86f342aaa5ca978092633d1dea8ded465b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiaxi=20=C2=AE?= <4772169+renzhexigua@users.noreply.github.com> Date: Sun, 12 Feb 2023 00:36:32 +0800 Subject: [PATCH] fix(route): remove next() from mesalab route (#11835) * fix(route): remove next() from mesalab route * refactor: migrate to v2 http://www.sim.cas.cn/xwzx2016/xshd2016/ is dead --------- --- docs/university.md | 14 ++--- lib/router.js | 8 +-- lib/routes/universities/cas/mesalab/kb.js | 45 -------------- lib/routes/universities/cas/sim/academic.js | 59 ------------------- .../universities => v2}/cas/cg/index.js | 6 +- .../universities => v2}/cas/iee/kydt.js | 12 ++-- lib/v2/cas/maintainer.js | 6 ++ lib/v2/cas/mesalab/kb.js | 41 +++++++++++++ lib/v2/cas/radar.js | 40 +++++++++++++ lib/v2/cas/router.js | 6 ++ lib/v2/cas/sim/kyjz.js | 47 +++++++++++++++ 11 files changed, 162 insertions(+), 122 deletions(-) delete mode 100644 lib/routes/universities/cas/mesalab/kb.js delete mode 100644 lib/routes/universities/cas/sim/academic.js rename lib/{routes/universities => v2}/cas/cg/index.js (83%) rename lib/{routes/universities => v2}/cas/iee/kydt.js (78%) create mode 100644 lib/v2/cas/maintainer.js create mode 100644 lib/v2/cas/mesalab/kb.js create mode 100644 lib/v2/cas/radar.js create mode 100644 lib/v2/cas/router.js create mode 100644 lib/v2/cas/sim/kyjz.js diff --git a/docs/university.md b/docs/university.md index 5ab57cd616..cfe0830b19 100644 --- a/docs/university.md +++ b/docs/university.md @@ -3477,7 +3477,7 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 成果转化 - + | 工作动态 | 科技成果转移转化亮点工作 | | ---- | ------------ | @@ -3485,17 +3485,17 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS -### 上海微系统与信息技术研究所学术活动 +### 上海微系统与信息技术研究所 科技进展 - + -### 中国科学院信息工程研究所 第二研究室 处理架构组 知识库 +### 信息工程研究所 第二研究室 处理架构组 知识库 - + -### 中国科学院电工研究所 科研动态 +### 电工研究所 科研动态 - + ## 中国科学院大学 diff --git a/lib/router.js b/lib/router.js index 6a91e0af20..e9a9532c30 100644 --- a/lib/router.js +++ b/lib/router.js @@ -590,10 +590,10 @@ router.get('/scnu/cs/match', lazyloadRouteHandler('./routes/universities/scnu/cs // router.get('/gdut/news', lazyloadRouteHandler('./routes/universities/gdut/news')); // 中国科学院 -router.get('/cas/sim/academic', lazyloadRouteHandler('./routes/universities/cas/sim/academic')); -router.get('/cas/mesalab/kb', lazyloadRouteHandler('./routes/universities/cas/mesalab/kb')); -router.get('/cas/iee/kydt', lazyloadRouteHandler('./routes/universities/cas/iee/kydt')); -router.get('/cas/cg/:caty?', lazyloadRouteHandler('./routes/universities/cas/cg/index')); +// router.get('/cas/sim/academic', lazyloadRouteHandler('./routes/universities/cas/sim/academic')); +// router.get('/cas/mesalab/kb', lazyloadRouteHandler('./routes/universities/cas/mesalab/kb')); +// router.get('/cas/iee/kydt', lazyloadRouteHandler('./routes/universities/cas/iee/kydt')); +// router.get('/cas/cg/:caty?', lazyloadRouteHandler('./routes/universities/cas/cg/index')); // 中国传媒大学 // router.get('/cuc/yz', lazyloadRouteHandler('./v2/cuc/yz')); diff --git a/lib/routes/universities/cas/mesalab/kb.js b/lib/routes/universities/cas/mesalab/kb.js deleted file mode 100644 index 118f5e37aa..0000000000 --- a/lib/routes/universities/cas/mesalab/kb.js +++ /dev/null @@ -1,45 +0,0 @@ -const cherrio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx, next) => { - const homepage = 'https://www.mesalab.cn'; - const response = await got({ - method: 'get', - url: `${homepage}/f/article/articleList?pageNo=1&pageSize=15&createTimeSort=DESC`, - }); - - const $ = cherrio.load(response.data); - const articles = $('.aw-item').get(); - - const items = await Promise.all( - articles.map((item) => { - const article = $(item).find('.aw-item-content > p').first(); - const title = article - .text() - .replace(/(\r\n|\n|\r)/gm, ' ') - .trim(); - const link = `${homepage}/${article.find('a').attr('href')}`; - - return ctx.cache.tryGet(link, async () => { - const result = await got.get(link); - const $ = cherrio.load(result.body); - return { - title, - author: $('.user_name').text(), - pubDate: new Date($('.link_postdate').text().replace(/\s+/g, ' ')).toUTCString(), - description: $('#article_details').html(), - link, - }; - }); - }) - ); - - ctx.state.data = { - title: 'MESA 知识库', - description: '中国科学院信息工程研究所 第二研究室 处理架构组', - link: homepage, - item: items, - }; - - await next(); -}; diff --git a/lib/routes/universities/cas/sim/academic.js b/lib/routes/universities/cas/sim/academic.js deleted file mode 100644 index eefdae197c..0000000000 --- a/lib/routes/universities/cas/sim/academic.js +++ /dev/null @@ -1,59 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); - -const host = 'http://www.sim.cas.cn/'; - -module.exports = async (ctx) => { - const link = url.resolve(host, 'xwzx2016/xshd2016/'); - const response = await got.get(link); - - const $ = cheerio.load(response.data); - - const list = $('.list-news li') - .slice(0, 10) - .map((i, e) => - $(e).children().length > 0 - ? { - link: $(e).find('a').attr('href'), - date: $(e).find('span').text().replace('[', '').replace(']', ''), - } - : null - ) - .get(); - - const out = await Promise.all( - list.map(async (item) => { - const itemUrl = url.resolve(link, item.link); - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const response = await got.get(itemUrl); - const $ = cheerio.load(response.data); - - const author = $('.qtinfo.hidden-lg.hidden-md.hidden-sm').text(); - const reg = new RegExp('文章来源:(.*?)\\|', 'g'); - - const single = { - title: $('p.wztitle').text().trim(), - link: itemUrl, - author: reg.exec(author)[1].toString().trim(), - description: $('.TRS_Editor') - .html() - .replace(/src=".\//g, `src="${url.resolve(itemUrl, '.')}`) - .trim(), - pubDate: new Date(item.date).toUTCString(), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: '中国科学院上海微系统与信息技术研究所 -- 学术活动', - link, - item: out, - }; -}; diff --git a/lib/routes/universities/cas/cg/index.js b/lib/v2/cas/cg/index.js similarity index 83% rename from lib/routes/universities/cas/cg/index.js rename to lib/v2/cas/cg/index.js index 04e76f2fc7..b29a147d73 100644 --- a/lib/routes/universities/cas/cg/index.js +++ b/lib/v2/cas/cg/index.js @@ -1,11 +1,13 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { ctx.params.caty = ctx.params.caty || 'zh'; const rootUrl = 'https://www.cas.cn'; - const currentUrl = `${rootUrl}/cg/${ctx.params.caty}`; + const currentUrl = `${rootUrl}/cg/${ctx.params.caty}/`; const response = await got({ method: 'get', url: currentUrl, @@ -35,7 +37,7 @@ module.exports = async (ctx) => { const content = cheerio.load(detailResponse.data); item.description = content('.TRS_Editor').html(); - item.pubDate = new Date(content('meta[name="PubDate"]').attr('content') + ' GMT+8').toUTCString(); + item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), 8); return item; }) diff --git a/lib/routes/universities/cas/iee/kydt.js b/lib/v2/cas/iee/kydt.js similarity index 78% rename from lib/routes/universities/cas/iee/kydt.js rename to lib/v2/cas/iee/kydt.js index 525f69dccd..230f547749 100644 --- a/lib/routes/universities/cas/iee/kydt.js +++ b/lib/v2/cas/iee/kydt.js @@ -1,8 +1,10 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { - const rootUrl = 'http://www.iee.cas.cn/xwzx/kydt'; + const rootUrl = 'http://www.iee.cas.cn/xwzx/kydt/'; const response = await got({ method: 'get', url: rootUrl, @@ -11,15 +13,15 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); const list = $('li.entry .entry-content-title') .slice(0, 15) - .map((_, item) => { + .toArray() + .map((item) => { item = $(item); const a = item.find('a'); return { title: a.text(), link: a.attr('href'), }; - }) - .get(); + }); const items = await Promise.all( list.map((item) => @@ -31,7 +33,7 @@ module.exports = async (ctx) => { const content = cheerio.load(detailResponse.data); item.description = content('.article-content').html(); - item.pubDate = new Date(content('time').text().split(':')[1] + ' GMT+8').toUTCString(); + item.pubDate = timezone(parseDate(content('time').text().split(':')[1]), 8); return item; }) diff --git a/lib/v2/cas/maintainer.js b/lib/v2/cas/maintainer.js new file mode 100644 index 0000000000..36fd4aabd1 --- /dev/null +++ b/lib/v2/cas/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/cg/:caty?': ['nczitzk'], + '/iee/kydt': ['nczitzk'], + '/mesalab/kb': ['renzhexigua'], + '/sim/kyjz': ['HenryQW'], +}; diff --git a/lib/v2/cas/mesalab/kb.js b/lib/v2/cas/mesalab/kb.js new file mode 100644 index 0000000000..46cb231703 --- /dev/null +++ b/lib/v2/cas/mesalab/kb.js @@ -0,0 +1,41 @@ +const cherrio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const homepage = 'https://www.mesalab.cn'; + const url = `${homepage}/f/article/articleList?pageNo=1&pageSize=15&createTimeSort=DESC`; + const response = await got(url); + + const $ = cherrio.load(response.data); + const articles = $('.aw-item').toArray(); + + const items = await Promise.all( + articles.map((item) => { + const a = $(item).find('a').first(); + const title = a.text().trim(); + const link = `${homepage}${a.attr('href')}`; + + return ctx.cache.tryGet(link, async () => { + const result = await got(link); + const $ = cherrio.load(result.data); + return { + title, + author: $('.user_name').text(), + pubDate: timezone(parseDate($('.link_postdate').text().replace(/\s+/g, ' ')), 8), + description: $('#article_content').html() + ($('.attachment').length ? $('.attachment').html() : ''), + link, + category: $('.category .category_r span').first().text(), + }; + }); + }) + ); + + ctx.state.data = { + title: 'MESA 知识库', + description: '中国科学院信息工程研究所 第二研究室 处理架构组', + link: url, + item: items, + }; +}; diff --git a/lib/v2/cas/radar.js b/lib/v2/cas/radar.js new file mode 100644 index 0000000000..7602dcfd20 --- /dev/null +++ b/lib/v2/cas/radar.js @@ -0,0 +1,40 @@ +module.exports = { + 'cas.cn': { + _name: '中国科学院', + www: [ + { + title: '成果转化', + docs: 'https://docs.rsshub.app/university.html#zhong-guo-ke-xue-yuan', + source: ['/cg/:caty?'], + target: '/cas/cg/:caty?', + }, + ], + 'www.sim': [ + { + title: '上海微系统与信息技术研究所 - 科技进展', + docs: 'https://docs.rsshub.app/university.html#zhong-guo-ke-xue-yuan', + source: ['/xwzx2016/kyjz/', '/'], + target: '/cas/sim/kyjz', + }, + ], + 'www.iee': [ + { + title: '电工研究所 科研动态', + docs: 'https://docs.rsshub.app/university.html#zhong-guo-ke-xue-yuan', + source: ['/xwzx/kydt', '/'], + target: '/cas/iee/kydt', + }, + ], + }, + 'mesalab.cn': { + _name: '中国科学院', + www: [ + { + title: '信息工程研究所 第二研究室 处理架构组 知识库', + docs: 'https://docs.rsshub.app/university.html#zhong-guo-ke-xue-yuan', + source: ['/f/article/articleList', '/'], + target: '/cas/mesalab/kb', + }, + ], + }, +}; diff --git a/lib/v2/cas/router.js b/lib/v2/cas/router.js new file mode 100644 index 0000000000..61e4f597f9 --- /dev/null +++ b/lib/v2/cas/router.js @@ -0,0 +1,6 @@ +module.exports = (router) => { + router.get('/cg/:caty?', require('./cg/index')); + router.get('/iee/kydt', require('./iee/kydt')); + router.get('/mesalab/kb', require('./mesalab/kb')); + router.get('/sim/kyjz', require('./sim/kyjz')); +}; diff --git a/lib/v2/cas/sim/kyjz.js b/lib/v2/cas/sim/kyjz.js new file mode 100644 index 0000000000..891dd66893 --- /dev/null +++ b/lib/v2/cas/sim/kyjz.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const host = 'http://www.sim.cas.cn/'; + +module.exports = async (ctx) => { + const link = new URL('xwzx2016/kyjz/', host).href; + const response = await got(link); + + const $ = cheerio.load(response.data); + + const list = $('.list-news li') + .toArray() + .filter((e) => !$(e).attr('style')) + .map((e) => { + e = $(e); + return { + link: new URL(e.find('a').attr('href'), link).href, + pubDate: e.find('span').text().replace('[', '').replace(']', ''), + }; + }); + + const out = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + + const author = $('.qtinfo.hidden-lg.hidden-md.hidden-sm').text(); + const reg = /文章来源:(.*?)\|/g; + + item.title = $('p.wztitle').text().trim(); + item.author = reg.exec(author)[1].toString().trim(); + item.description = $('.TRS_Editor').html(); + item.pubDate = parseDate(item.pubDate); + return item; + }) + ) + ); + + ctx.state.data = { + title: '中国科学院上海微系统与信息技术研究所 -- 科技进展', + link, + item: out, + }; +};