From ddf5b0d004a6fbefc09b778face3b76c31a82437 Mon Sep 17 00:00:00 2001 From: Chunibyo <359806334@qq.com> Date: Tue, 9 Jun 2020 11:24:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=AD?= =?UTF-8?q?=E5=9B=BD=E5=9C=B0=E8=B4=A8=E5=A4=A7=E5=AD=A6=E5=8F=8A=E5=9C=B0?= =?UTF-8?q?=E7=90=86=E4=B8=8E=E4=BF=A1=E6=81=AF=E5=B7=A5=E7=A8=8B=E5=AD=A6?= =?UTF-8?q?=E9=99=A2=E7=9A=84=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#4927?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 8 +++ lib/router.js | 2 + lib/routes/cug/undergraduate.js | 86 +++++++++++++++++++++++++++++++++ lib/routes/cug/xgxy.js | 35 ++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 lib/routes/cug/undergraduate.js create mode 100644 lib/routes/cug/xgxy.js diff --git a/docs/university.md b/docs/university.md index 3b929a1f7..0f63abf42 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1681,6 +1681,14 @@ type 列表: +### 中国地质大学通知公告 + + + +### 地理与信息工程学院综合通知公告 + + + ## 中国海洋大学 ### 信息科学与工程学院 diff --git a/lib/router.js b/lib/router.js index a7595eab5..a97975ad4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2032,6 +2032,8 @@ router.get('/leemeng', require('./routes/blogs/leemeng')); // 中国地质大学 router.get('/cug/graduate', require('./routes/cug/graduate')); +router.get('/cug/undergraduate', require('./routes/cug/undergraduate')); +router.get('/cug/xgxy', require('./routes/cug/xgxy')); // 网易 - 网易号 router.get('/netease/dy/:id', require('./routes/netease/dy')); diff --git a/lib/routes/cug/undergraduate.js b/lib/routes/cug/undergraduate.js new file mode 100644 index 000000000..385fe035a --- /dev/null +++ b/lib/routes/cug/undergraduate.js @@ -0,0 +1,86 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + // 发起 HTTP GET 请求 + + const baseUrl = 'http://www.cug.edu.cn/index/tzgg.htm'; + + const response = await got({ + method: 'get', + url: baseUrl, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('#container > div > div > div.col-news > div.col-news-con > ul > li'); + + const out = await Promise.all( + list + .map(async (index, element) => { + element = $(element); + const link = element.find('a').attr('href'); + const description = await ctx.cache.tryGet(link, async () => { + const result = await got.get(link[0] === '.' ? `${baseUrl}/../${link}` : link); + const $ = cheerio.load(result.data); + return $('.read').html(); + }); + const item = { + title: element.find('a').text(), + link: link, + pubDate: new Date(element.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(), + description: description, + }; + return Promise.resolve(item); + }) + .get() + ); + + ctx.state.data = { + title: '中国地质大学(武汉) - 综合通知公告', + link: baseUrl, + item: out, + }; + + /* + + async function getDescription(_link) { + try { + const response = await got({ + method: 'get', + url: _link[0] === '.' ? `${baseUrl}/../${_link}` : _link, + }); + const data = response.data; + const $ = cheerio.load(data); + return $('.read span').text(); + } catch (e) { + return '未取到数据'; + } + } + + const descriptionPromises = list.map((index, item) => getDescription($(item).find('a').attr('href'))).get(); + + const descriptions = await Promise.all(descriptionPromises); + + ctx.state.data = { + title: '中国地质大学(武汉) - 综合通知公告', + link: baseUrl, + item: + list && + list + .map((index, item) => { + item = $(item); + const _link = item.find('a').attr('href'); + return { + title: item.find('a').text(), + link: _link, + pubDate: new Date(item.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(), + description: descriptions[index], + }; + }) + .get(), + }; + + */ +}; diff --git a/lib/routes/cug/xgxy.js b/lib/routes/cug/xgxy.js new file mode 100644 index 000000000..ebb9228c3 --- /dev/null +++ b/lib/routes/cug/xgxy.js @@ -0,0 +1,35 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + // 发起 HTTP GET 请求 + + const baseUrl = 'http://xgxy.cug.edu.cn/index/tzgg.htm'; + + const response = await got({ + method: 'get', + url: baseUrl, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('#content > section.section.full-width-bg.gray-bg > div > div > div > ul > li'); + + ctx.state.data = { + title: '中国地质大学(武汉)地理与信息工程学院 - 综合通知公告', + link: baseUrl, + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('a').text(), + link: item.find('a').attr('href'), + pubDate: new Date(item.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(), + }; + }) + .get(), + }; +};