diff --git a/docs/README.md b/docs/README.md index 4c5e9f24e4..21f08a3ba9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1284,6 +1284,14 @@ GitHub 官方也提供了一些 RSS: + + +| 信息通告 | 奖学金 | 助学金 | 讲座活动 | 党团活动 | 新闻发布 | +| -------- | ----------- | ------------ | -------- | -------- | -------- | +| 空 | scholarship | financialAid | lecture | activity | news | + + + ### 中国科学院 diff --git a/router.js b/router.js index 166e176c7a..45d103d6d1 100644 --- a/router.js +++ b/router.js @@ -551,6 +551,7 @@ router.get('/sjtu/seiee/bjwb/major_transfer', require('./routes/universities/sjt router.get('/sjtu/seiee/bjwb/postgraduate', require('./routes/universities/sjtu/seiee/bjwb/postgraduate')); router.get('/sjtu/seiee/bjwb/abroad', require('./routes/universities/sjtu/seiee/bjwb/abroad')); router.get('/sjtu/seiee/bjwb/international', require('./routes/universities/sjtu/seiee/bjwb/international')); +router.get('/sjtu/seiee/xsb/:type?', require('./routes/universities/sjtu/seiee/xsb')); router.get('/sjtu/gs/tzgg/:type?', require('./routes/universities/sjtu/gs/tzgg')); diff --git a/routes/universities/sjtu/seiee/xsb.js b/routes/universities/sjtu/seiee/xsb.js new file mode 100644 index 0000000000..be4ffa384a --- /dev/null +++ b/routes/universities/sjtu/seiee/xsb.js @@ -0,0 +1,86 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://xsb.seiee.sjtu.edu.cn'; +const config = { + news: { + link: `xsb/list/2938-1-20.htm`, + title: '新闻发布', + }, + scholarship: { + link: `xsb/list/611-1-20.htm`, + title: '奖学金', + }, + activity: { + link: `xsb/list/2676-1-20.htm`, + title: '党团活动', + }, + lecture: { + link: `xsb/list/1981-1-20.htm`, + title: '讲座活动', + }, + all: { + link: `xsb/list/705-1-20.htm`, + title: '信息通告', + }, + financialAid: { + link: `xsb/list/1001-1-20.htm`, + title: '助学金', + }, +}; + +module.exports = async (ctx) => { + let type = ctx.params.type; + type = type ? type : 'all'; + const link = url.resolve(host, config[type].link); + const response = await axios.get(link); + + const $ = cheerio.load(response.data); + + const list = $('.list_box_5_2 li') + .map((i, e) => ({ + date: $(e) + .children('span') + .text() + .slice(1, -1), + title: $(e) + .children('a') + .text() + .slice(1), + link: $(e) + .children('a') + .attr('href'), + })) + .get(); + + const out = await Promise.all( + list.map(async (item) => { + const itemUrl = url.resolve(host, item.link); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + const single = { + title: item.title, + link: itemUrl, + author: '上海交通大学电子信息与电气工程学院学生工作办公室', + description: $('.article_box') + .text() + .slice(0, -7), + pubDate: new Date(item.date), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title, + link, + item: out, + }; +};