From 1d6a70a152bd77c2ca0d77636fa56ab5f474d678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E7=8E=8B=E5=B7=9E=E3=82=A2=E3=83=86=E3=83=8D?= Date: Sun, 31 Jul 2022 02:51:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=9C=E5=8C=97?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E5=8C=BB=E5=AD=A6=E4=B8=8E=E7=94=9F=E7=89=A9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=B7=A5=E7=A8=8B=E5=AD=A6=E9=99=A2=20(#1034?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 东北大学医学与生物信息工程学院 * Update lib/routes/universities/neu/bmie.js Co-authored-by: Tony * Update lib/routes/universities/neu/bmie.js Co-authored-by: Tony * fix(route): 更新BMIE 格式化日期、采用V2路由 * Apply suggestions from code review Co-authored-by: Tony * fix(route):采用 pubDate 解析 * refactor: migrate to v2 Co-authored-by: Athena --- docs/university.md | 48 +++++++++++++-- lib/router.js | 2 +- lib/routes/universities/neu/news.js | 61 ------------------- lib/v2/neu/bmie.js | 94 +++++++++++++++++++++++++++++ lib/v2/neu/maintainer.js | 4 ++ lib/v2/neu/news.js | 44 ++++++++++++++ lib/v2/neu/radar.js | 21 +++++++ lib/v2/neu/router.js | 4 ++ 8 files changed, 211 insertions(+), 67 deletions(-) delete mode 100644 lib/routes/universities/neu/news.js create mode 100644 lib/v2/neu/bmie.js create mode 100644 lib/v2/neu/maintainer.js create mode 100644 lib/v2/neu/news.js create mode 100644 lib/v2/neu/radar.js create mode 100644 lib/v2/neu/router.js diff --git a/docs/university.md b/docs/university.md index e83f9868f..83c97e8aa 100644 --- a/docs/university.md +++ b/docs/university.md @@ -891,13 +891,51 @@ xskb1 对应 ## 东北大学 -### 东北大学新闻网 +### 新闻网 - + -| 东大要闻 | 媒体东大 | 通知公告 | 新闻纵横 | 人才培养 | 学术科研 | 英文新闻 | 招生就业 | 考研出国 | 校园文学 | 校友风采 | 时事热点 | 教育前沿 | 文化体育 | 最新科技 | -| ---- | ---- | ---- | ---- | ---: | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | -| ddyw | mtdd | tzgg | xwzh | rcpy | xsky | 217 | zsjy | kycg | xywx | xyfc | ssrd | jyqy | whty | zxkj | +| 种类名 | 参数 | +| ---- | ---- | +| 东大要闻 | ddyw | +| 媒体东大 | mtdd | +| 通知公告 | tzgg | +| 新闻纵横 | xwzh | +| 人才培养 | rcpy | +| 学术科研 | xsky | +| 英文新闻 | 217 | +| 招生就业 | zsjy | +| 考研出国 | kycg | +| 校园文学 | xywx | +| 校友风采 | xyfc | +| 时事热点 | ssrd | +| 教育前沿 | jyqy | +| 文化体育 | whty | +| 最新科技 | zxkj | + + + +### 医学与生物信息工程学院 + + + +| Id | 名称 | +| ---------------------- | ----- | +| news | 学院新闻 | +| academic | 学术科研 | +| talent_development | 人才培养 | +| international_exchange | 国际交流 | +| announcement | 通知公告 | +| undergraduate_dev | 本科生培养 | +| postgraduate_dev | 研究生培养 | +| undergraduate_recruit | 本科生招募 | +| postgraduate_recruit | 研究生招募 | +| CPC_build | 党的建设 | +| CPC_work | 党委工作 | +| union_work | 工会工作 | +| CYL_work | 共青团工作 | +| security_management | 安全管理 | +| alumni_style | 校友风采 | diff --git a/lib/router.js b/lib/router.js index a115feb2b..0788848d2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2473,7 +2473,7 @@ router.get('/haohaozhu/whole-house/:keyword?', lazyloadRouteHandler('./routes/ha router.get('/haohaozhu/discover/:keyword?', lazyloadRouteHandler('./routes/haohaozhu/discover')); // 东北大学 -router.get('/neu/news/:type', lazyloadRouteHandler('./routes/universities/neu/news')); +// router.get('/neu/news/:type', lazyloadRouteHandler('./routes/universities/neu/news')); // 快递100 router.get('/kuaidi100/track/:number/:id/:phone?', lazyloadRouteHandler('./routes/kuaidi100/index')); diff --git a/lib/routes/universities/neu/news.js b/lib/routes/universities/neu/news.js deleted file mode 100644 index bb60ad051..000000000 --- a/lib/routes/universities/neu/news.js +++ /dev/null @@ -1,61 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -const baseUrl = 'https://neunews.neu.edu.cn'; -module.exports = async (ctx) => { - const type = ctx.params.type; - const newsUrl = `${baseUrl}/${type}/list.htm`; - const response = await got({ - method: 'get', - url: newsUrl, - }); - - const data = response.data; - const $ = cheerio.load(data); - - const title = $('title').text(); - const items = $('.column-news-list > .news_list > .news > .news_title').slice(0, 5).get(); - const results = await Promise.all( - items.map(async (item) => { - const $ = cheerio.load(item); - const title = $('a').attr('title'); - const url = baseUrl + $('a').attr('href'); - const description = await ctx.cache.tryGet(url, async () => { - const result = await got.get(url); - const $ = cheerio.load(result.data); - // 处理部分格式 - $('article') - .find('span') - .each(function () { - const temp = $(this).text(); - $(this).replaceWith(temp); - }); - $('article') - .find('div') - .each(function () { - const temp = $(this).html(); - $(this).replaceWith(temp); - }); - $('article').find('a').remove(); - $('article') - .find('p') - .each(function () { - $(this).removeAttr('style'); - $(this).removeAttr('class'); - }); - return $('article').html(); - }); - const result = { - title, - description, - link: url, - }; - return Promise.resolve(result); - }) - ); - ctx.state.data = { - title: `东北大学新闻网-${title}`, - link: newsUrl, - item: results, - }; -}; diff --git a/lib/v2/neu/bmie.js b/lib/v2/neu/bmie.js new file mode 100644 index 000000000..1abda71e4 --- /dev/null +++ b/lib/v2/neu/bmie.js @@ -0,0 +1,94 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const baseUrl = 'http://www.bmie.neu.edu.cn'; + +const map = { + news: 561, + academic: 562, + talent_development: 563, + international_exchange: 'gjjl3', + announcement: 564, + undergraduate_dev: 573, + postgraduate_dev: 574, + undergraduate_recruit: 'bks', + postgraduate_recruit: 574, + CPC_build: 556, + CPC_work: 576, + union_work: 577, + CYL_work: 'gqtgz', + security_management: 569, + alumni_style: 557, +}; + +module.exports = async (ctx) => { + let type = ctx.params.type; + if (typeof map[type] !== 'undefined') { + type = map[type]; + } + const newsUrl = `${baseUrl}/${type}/list.htm`; + const response = await got(newsUrl); + + const data = response.data; + const $ = cheerio.load(data); + + const title = $('title').text(); + const items = $('#subIndex > div.main_frame_sub > div.detail_sub > div > div > div > ul > li').slice(0, 7).get(); + const results = await Promise.all( + items.map(async (item) => { + const $ = cheerio.load(item); + const title = $('a').attr('title'); + const url = baseUrl + $('a').attr('href'); + const data = await ctx.cache.tryGet(url, async () => { + const result = await got(url); + const $ = cheerio.load(result.data); + + const info = $($('.ny_con p')[1]).text(); + const s = info.search(/\d{4}-\d{2}-\d{2}/); + const date = info.substring(s, s + 10); + + const au_start = info.indexOf('作者:') + 3; + const au_end = info.lastIndexOf('|'); + const auhor = info.substring(au_start, au_end).trim(); + $('.entry') + .find('span') + .each(function () { + const temp = $(this).text(); + $(this).replaceWith(temp); + }); + $('.entry') + .find('div') + .each(function () { + const temp = $(this).html(); + $(this).replaceWith(temp); + }); + $('.entry').find('a').remove(); + $('.entry') + .find('p') + .each(function () { + $(this).removeAttr('style'); + $(this).removeAttr('class'); + }); + $('.wp_art_adjoin').remove(); + return { description: $('.entry').html(), date, author: auhor }; + }); + const description = data.description; + const pubDate = parseDate(data.date); + const author = data.author; + const result = { + title, + description, + link: url, + pubDate, + author, + }; + return result; + }) + ); + ctx.state.data = { + title: `东北大学 医学与生物信息工程学院 ${title}`, + link: newsUrl, + item: results, + }; +}; diff --git a/lib/v2/neu/maintainer.js b/lib/v2/neu/maintainer.js new file mode 100644 index 000000000..591fbadb3 --- /dev/null +++ b/lib/v2/neu/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/bmie/:type': ['tennousuathena'], + '/news/:type': ['JeasonLau'], +}; diff --git a/lib/v2/neu/news.js b/lib/v2/neu/news.js new file mode 100644 index 000000000..9545c38b7 --- /dev/null +++ b/lib/v2/neu/news.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const baseUrl = 'https://neunews.neu.edu.cn'; + +module.exports = async (ctx) => { + const type = ctx.params.type; + const newsUrl = `${baseUrl}/${type}/list.htm`; + const response = await got(newsUrl); + + const data = response.data; + const $ = cheerio.load(data); + + const items = $('.column-news-list > .news_list > .news') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').attr('title'), + link: new URL(item.find('a').attr('href'), baseUrl).href, + pubDate: parseDate(item.find('.news_meta').text(), 'YYYY-MM-DD'), + }; + }); + + const results = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const result = await got(item.link); + const $ = cheerio.load(result.data); + + item.author = $('.arti-metas').text().split('更新日期')[0]; + item.description = $('.article_content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `东北大学新闻网-${$('head title').text()}`, + link: newsUrl, + item: results, + }; +}; diff --git a/lib/v2/neu/radar.js b/lib/v2/neu/radar.js new file mode 100644 index 000000000..5606e37cf --- /dev/null +++ b/lib/v2/neu/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'neu.edu.cn': { + _name: '东北大学', + neunews: [ + { + title: '新闻网', + docs: 'https://docs.rsshub.app/university.html#dong-bei-da-xue', + source: ['/:type/list.htm'], + target: '/neu/news/:type', + }, + ], + 'www.bmie': [ + { + title: '学院新闻 - 医学与生物信息工程学院', + docs: 'https://docs.rsshub.app/university.html#dong-bei-da-xue', + source: ['/'], + target: '/neu/bmie/news', + }, + ], + }, +}; diff --git a/lib/v2/neu/router.js b/lib/v2/neu/router.js new file mode 100644 index 000000000..fe650264a --- /dev/null +++ b/lib/v2/neu/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/bmie/:type', require('./bmie')); + router.get('/news/:type', require('./news')); +};