From eaa77b9365d34e8434347f1fbf56a11d25c2ae8b Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Wed, 29 Aug 2018 10:21:15 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E4=B8=8A=E6=B5=B7=E4=BA=A4=E9=80=9A?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E7=94=B5=E5=AD=90=E4=BF=A1=E6=81=AF=E4=B8=8E?= =?UTF-8?q?=E7=94=B5=E6=B0=94=E5=B7=A5=E7=A8=8B=E5=AD=A6=E9=99=A2=20--=20?= =?UTF-8?q?=E5=AD=A6=E6=9C=AF=E5=8A=A8=E6=80=81=20(#567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add 上海交通大学电子信息与电气工程学院 -- 学术动态 * Add docs * Fix date * Update docs * Fix img link --- README.md | 3 +++ docs/README.md | 8 ++++++ router.js | 3 +++ routes/sjtu/seiee/academic.js | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 routes/sjtu/seiee/academic.js diff --git a/README.md b/README.md index cd62a20cc5..469782da04 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 文章 - 大连工业大学 - 教务处新闻 +- 上海交通大学 + - 电子信息与电气工程学院 + - 学术动态 - 中国科学院 - 上海微系统与信息技术研究所 - 学术活动 diff --git a/docs/README.md b/docs/README.md index 9093f47732..f55daee698 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2223,6 +2223,14 @@ type,分类 参数: 无 +## 上海交通大学 + +### 电子信息与电气工程学院 -- 学术动态 + +举例: [https://rsshub.app/sjtu/seiee/academic](https://rsshub.app/sjtu/seiee/academic) + +路由: `/sjtu/seiee/academic` + ## 中国科学院 ### 上海微系统与信息技术研究所 -- 学术活动 diff --git a/router.js b/router.js index 90607f4e55..93efe3185b 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('/sjtu/seiee/academic', require('./routes/sjtu/seiee/academic')); + // 中国科学院 router.get('/cas/sim/academic', require('./routes/cas/sim/academic')); diff --git a/routes/sjtu/seiee/academic.js b/routes/sjtu/seiee/academic.js new file mode 100644 index 0000000000..6a87fe848d --- /dev/null +++ b/routes/sjtu/seiee/academic.js @@ -0,0 +1,51 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://www.seiee.sjtu.edu.cn/'; + +module.exports = async (ctx) => { + const link = url.resolve(host, 'seiee/list/683-1-20.htm'); + const response = await axios.get(link); + + const $ = cheerio.load(response.data); + + const list = $('.list_style_1 li a') + .map((i, e) => $(e).attr('href')) + .get(); + + const out = await Promise.all( + list.map(async (itemUrl) => { + itemUrl = url.resolve(host, itemUrl); + 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: $('h2.title_3').text(), + link: itemUrl, + author: '上海交通大学电子信息与电气工程学院', + description: $('.c_1.article_content') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`), + pubDate: new Date( + $('.date_1 span:first-of-type') + .text() + .trim() + ), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '上海交通大学电子信息与电气工程学院 -- 学术动态', + link, + item: out, + }; +};