From db06a017979c22fac4d1a62ecbad8adeb903e38d Mon Sep 17 00:00:00 2001 From: talen Date: Mon, 17 Sep 2018 18:45:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=9B=E5=B7=9D=E6=97=85?= =?UTF-8?q?=E6=B8=B8=E5=AD=A6=E9=99=A2RSS=20(#727)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加四川旅游学院教务处RSS,第一次pull request,多有不足,请多指正,谢谢 --- docs/README.md | 14 +++++++++++ router.js | 4 +++ routes/universities/sctu/jwc.js | 42 ++++++++++++++++++++++++++++++++ routes/universities/sctu/xgxy.js | 39 +++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 routes/universities/sctu/jwc.js create mode 100644 routes/universities/sctu/xgxy.js diff --git a/docs/README.md b/docs/README.md index 4535813d4b..9ca4e5d853 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1095,6 +1095,20 @@ category 列表: +### 四川旅游学院 + + + + + + + +| 教务通知 | 信息公告 | +| -------- | -------- | +| 13 | 14 | + + + ## 传统媒体 ### 央视新闻 diff --git a/router.js b/router.js index 4867cd3ea7..a8976cacd7 100644 --- a/router.js +++ b/router.js @@ -527,6 +527,10 @@ router.get('/cqust/lib/:type?', require('./routes/universities/cqust/lib')); router.get('/cczu/jwc/:category?', require('./routes/universities/cczu/jwc')); router.get('/cczu/news/:category?', require('./routes/universities/cczu/news')); +// 四川旅游学院 +router.get('/sctu/xgxy', require('./routes/universities/sctu/xgxy')); +router.get('/sctu/jwc/:type?', require('./routes/universities/sctu/jwc')); + // ifanr router.get('/ifanr/appso', require('./routes/ifanr/appso')); diff --git a/routes/universities/sctu/jwc.js b/routes/universities/sctu/jwc.js new file mode 100644 index 0000000000..035b124f29 --- /dev/null +++ b/routes/universities/sctu/jwc.js @@ -0,0 +1,42 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const dirname = 'http://www.sctu.edu.cn/jwc/'; + const response = await axios({ + method: 'get', + url: `${dirname}list.asp?type=12&fl=${+ctx.params.type === 14 ? 14 : 13}`, + responseType: 'arraybuffer', + headers: { + Referer: 'http://www.sctu.edu.cn', + }, + }); + + // HTML-buffer转为gb2312 + const data = iconv.decode(response.data, 'gb2312'); + + const $ = cheerio.load(data); + + const list = $('#list1 ul li'); + + ctx.state.data = { + title: '四川旅游学院首页', + link: 'http://www.sctu.edu.cn', + description: $('meta[name="description"]').attr('content'), + item: + list && + list + .map((index, item) => { + item = $(item); + + return { + title: $(item.find('a')).text(), + pubDate: $(item.find('dl')).text(), + description: `发布日期:${$(item.find('dl')).text()}`, + link: `${dirname + $(item.find('a')).attr('href')}`, + }; + }) + .get(), + }; +}; diff --git a/routes/universities/sctu/xgxy.js b/routes/universities/sctu/xgxy.js new file mode 100644 index 0000000000..5f94ea1a5a --- /dev/null +++ b/routes/universities/sctu/xgxy.js @@ -0,0 +1,39 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + url: 'http://it.sctu.edu.cn/list.asp?fa=2&fl=12&zi=0', + responseType: 'arraybuffer', + headers: { + Referer: 'http://it.sctu.edu.cn/', + }, + }); + // HTML-buffer转为gb2312 + const data = iconv.decode(response.data, 'gb2312'); + + const $ = cheerio.load(data); + + const list = $('.list_dt a'); + + ctx.state.data = { + title: '四川旅游学院首页', + link: 'http://www.sctu.edu.cn', + description: $('meta[name="description"]').attr('content'), + item: + list && + list + .map((index, item) => { + item = $(item); + + return { + title: $(item.find('div')[0]).text(), + description: $(item.find('div')[1]).text(), + link: `http://it.sctu.edu.cn/${item.attr('href')}`, + }; + }) + .get(), + }; +};