From 10e0a988b1582d2631284e1df57cf9c2dd78b57f Mon Sep 17 00:00:00 2001 From: AngUOI <2503894740@QQ.COM> Date: Wed, 28 Aug 2019 18:14:46 +0800 Subject: [PATCH] feat: add lit jwc (#2948) 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/lit/jwc.js | 55 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/routes/universities/lit/jwc.js diff --git a/docs/university.md b/docs/university.md index 8bb28890f1..4cd43ea5bb 100644 --- a/docs/university.md +++ b/docs/university.md @@ -440,6 +440,12 @@ category 列表: +## 洛阳理工学院 + +### 教务处 + + + ## 南昌航空大学 ### 教务处公告与新闻 diff --git a/lib/router.js b/lib/router.js index 6893b3b68d..34a002b2d5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -529,6 +529,9 @@ router.get('/sjtu/jwc/:type?', require('./routes/universities/sjtu/jwc')); // 江南大学 router.get('/ju/jwc/:type?', require('./routes/universities/ju/jwc')); +// 洛阳理工学院 +router.get('/lit/jwc', require('./routes/universities/lit/jwc')); + // 北京大学 router.get('/pku/eecs/:type?', require('./routes/universities/pku/eecs')); diff --git a/lib/routes/universities/lit/jwc.js b/lib/routes/universities/lit/jwc.js new file mode 100644 index 0000000000..cfb3353368 --- /dev/null +++ b/lib/routes/universities/lit/jwc.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const host = 'http://www.lit.edu.cn/jwc/'; +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: host, + }); + + const $ = cheerio.load(response.data); + const items = []; + + // 获取头条文章 + $('article.ulist').each(function() { + const list = $(this); + items.push({ + title: `【头条】 ` + list.find('a').text(), + description: list.find('a').text(), + pubDate: list + .find('span') + .eq(-1) + .text(), + link: host + list.find('a').attr('href'), + }); + }); + + // 获取其它文章 + $('article.post_box').each(function() { + const list = $(this); + const ddate = list + .find('.c-top') + .children('div') + .text() + .trim(); + items.push({ + title: list.find('a').attr('title'), + description: list.children('.c-con').text(), + pubDate: ddate.substring(0, 4) + `-` + ddate.substring(4), + link: host + list.find('a').attr('href'), + }); + }); + + ctx.state.data = { + title: `洛理教务在线`, + link: host, + description: `规范管理 用心服务 欢迎您访问!`, + item: items.map((item) => ({ + title: item.title, + description: item.description, + pubDate: item.pubDate, + link: item.link, + })), + }; +};