From 7a187cb264211fa7e4c0cc736ae124d5a7eee94b Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 1 Aug 2020 23:59:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=9B=9B=E5=B7=9D=E8=81=8C?= =?UTF-8?q?=E4=B8=9A=E6=8A=80=E6=9C=AF=E5=AD=A6=E9=99=A2=E5=AD=A6=E9=99=A2?= =?UTF-8?q?=E5=85=AC=E5=91=8A=20(#5304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 6 ++++ lib/router.js | 3 ++ lib/routes/universities/scvtc/xygg.js | 46 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/universities/scvtc/xygg.js diff --git a/docs/university.md b/docs/university.md index 48707a8744..4a0354a7b9 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1409,6 +1409,12 @@ type 列表: +## 四川职业技术学院 + +### 学院公告 + + + ## 天津大学 ### 天津大学教务处 diff --git a/lib/router.js b/lib/router.js index 49c55ebdd1..1e1ffdaffa 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3040,6 +3040,9 @@ router.get('/hfut/tzgg', require('./routes/universities/hfut/tzgg')); // Darwin Awards router.get('/darwinawards/all', require('./routes/darwinawards/articles')); +// 四川职业技术学院 +router.get('/scvtc/xygg', require('./routes/universities/scvtc/xygg')); + // OneJAV router.get('/onejav/:type/:key?', require('./routes/onejav/one')); diff --git a/lib/routes/universities/scvtc/xygg.js b/lib/routes/universities/scvtc/xygg.js new file mode 100644 index 0000000000..0f150d0294 --- /dev/null +++ b/lib/routes/universities/scvtc/xygg.js @@ -0,0 +1,46 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = 'http://scvtc.edu.cn/ggfw1/xygg.htm'; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('div.list_l div ul li') + .map((_, item) => { + item = $(item); + const a = item.find('a[title]'); + return { + title: a.text(), + link: url.resolve(currentUrl, a.attr('href')), + pubDate: new Date(item.find('span.c43271_date').text().split(' ')[0].trim()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('#vsb_content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '四川职业技术学院 - 学院公告', + link: currentUrl, + item: items, + }; +};