From 0c3f41d5525cf7f2610a80047d2667f7b1f58e53 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Wed, 29 Aug 2018 10:26:12 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E4=B8=8A=E6=B5=B7=E7=A7=91=E6=8A=80?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E4=BF=A1=E6=81=AF=E7=A7=91=E6=8A=80=E4=B8=8E?= =?UTF-8?q?=E6=8A=80=E6=9C=AF=E5=AD=A6=E9=99=A2=20--=20=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=20(#568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #566 --- README.md | 3 ++ docs/README.md | 8 ++++ router.js | 3 ++ routes/shanghaitech/sist/activity.js | 59 ++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 routes/shanghaitech/sist/activity.js diff --git a/README.md b/README.md index 469782da04..b905676a65 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 文章 - 大连工业大学 - 教务处新闻 +- 上海科技大学 + - 信息科技与技术学院 + - 活动 - 上海交通大学 - 电子信息与电气工程学院 - 学术动态 diff --git a/docs/README.md b/docs/README.md index f55daee698..cd9500a0a8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2223,6 +2223,14 @@ type,分类 参数: 无 +## 上海科技大学 + +### 信息科技与技术学院 -- 活动 + +举例: [https://rsshub.app/shanghaitech/sist/activity](https://rsshub.app/shanghaitech/sist/activity) + +路由: `/shanghaitech/sist/activity` + ## 上海交通大学 ### 电子信息与电气工程学院 -- 学术动态 diff --git a/router.js b/router.js index 93efe3185b..2f2adcbce6 100755 --- a/router.js +++ b/router.js @@ -473,6 +473,9 @@ router.get('/mygalgame', require('./routes/galgame/mygalgame')); // DPU router.get('/dpu/jiaowu/:type?', require('./routes/dpu/jiaowu')); +// 上海科技大学 +router.get('/shanghaitech/sist/activity', require('./routes/shanghaitech/sist/activity')); + // 上海交通大学 router.get('/sjtu/seiee/academic', require('./routes/sjtu/seiee/academic')); diff --git a/routes/shanghaitech/sist/activity.js b/routes/shanghaitech/sist/activity.js new file mode 100644 index 0000000000..e49ce4c58d --- /dev/null +++ b/routes/shanghaitech/sist/activity.js @@ -0,0 +1,59 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://sist.shanghaitech.edu.cn/'; + +module.exports = async (ctx) => { + const link = url.resolve(host, 'cn/News.asp?mid=102'); + const response = await axios.get(link); + + const $ = cheerio.load(response.data); + + const list = $('.pagebv tr') + .slice(0, 10) + .map((i, e) => ({ + link: $(e) + .find('td:nth-of-type(2) a') + .attr('href'), + date: $(e) + .find('td:last-of-type') + .text() + .replace('[', '') + .replace(']', ''), + })) + .get(); + + const out = await Promise.all( + list.map(async (item) => { + const itemUrl = url.resolve(host, `cn/${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: $('.pagebv tr:first-of-type') + .text() + .trim(), + link: itemUrl, + author: '上海科技大学信息科技与技术学院', + description: $('.pagebv tr:last-of-type') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`) + .trim(), + pubDate: new Date(item.date), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '上海科技大学信息科技与技术学院 -- 活动', + link, + item: out, + }; +};