From 3cc4919ef2f693198bc5f23cc1cc92b31c27a72c Mon Sep 17 00:00:00 2001 From: Yangjie Xu Date: Wed, 29 Aug 2018 01:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=A7=E8=BF=9E=E5=B7=A5?= =?UTF-8?q?=E4=B8=9A=E5=A4=A7=E5=AD=A6=E6=95=99=E5=8A=A1=E5=A4=84=E6=96=B0?= =?UTF-8?q?=E9=97=BB=20(#563)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ docs/README.md | 14 ++++++++++++++ router.js | 3 +++ routes/dpu/jiaowu.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 routes/dpu/jiaowu.js diff --git a/README.md b/README.md index f15307cbd7..a2c6316dd1 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 全国气象预警 - Gitlab - Explore +- 大连工业大学 + - 教务处新闻 diff --git a/docs/README.md b/docs/README.md index ba4c9cc45c..ea9b547b66 100644 --- a/docs/README.md +++ b/docs/README.md @@ -290,6 +290,20 @@ type, 可选, 默认为 `all` | -------- | -------- | ---------- | -------- | -------- | -------- | -------- | -------- | -------- | | 实践创新 | 学科竞赛 | 研究生助教 | 教学改革 | 专业建设 | 课程建设 | 教材建设 | 教学成果 | 学术报告 | +### 大连工业大学 + +#### 教务处新闻 + +举例: [https://rsshub.app/dpu/jiaowu/xwdt](https://rsshub.app/dpu/jiaowu/xwdt) + +路由: `/dpu/jiaowu/:type?` + +参数: type, 可选, 默认为 `xwdt` + +| 新闻动态 | 通知公告 | 教务文件 | +| -------- | -------- | -------- | +| xwdt | tzgg | jwwj | + ## 媒体类 ### 央视新闻 diff --git a/router.js b/router.js index 9ff27efd8a..e931ad8712 100755 --- a/router.js +++ b/router.js @@ -467,4 +467,7 @@ router.get('/weatherAlarm', require('./routes/weatherAlarm')); // Gitlab router.get('/gitlab/explore/:type', require('./routes/gitlab/explore')); +// DPU +router.get('/dpu/jiaowu/:type?', require('./routes/dpu/jiaowu')); + module.exports = router; diff --git a/routes/dpu/jiaowu.js b/routes/dpu/jiaowu.js new file mode 100644 index 0000000000..226765e096 --- /dev/null +++ b/routes/dpu/jiaowu.js @@ -0,0 +1,44 @@ +const axios = require('../../utils/axios'); +const iconv = require('iconv-lite'); +const cheerio = require('cheerio'); +const resolve_url = require('url').resolve; + +const base_url = 'http://jiaowu.dlpu.edu.cn'; + +const map = { + xwdt: '/more/2', + tzgg: '/more/3', + jwwj: '/more/4', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'xwdt'; + const link = `${base_url}${map[type]}`; + + const response = await axios({ + method: 'get', + url: link, + responseType: 'arraybuffer', + headers: { + Referer: base_url, + }, + }); + + const $ = cheerio.load(iconv.decode(response.data, 'gb2312')); + + ctx.state.data = { + link: link, + title: $('#more>h1').text(), + item: $('.more_list>li') + .map((_, elem) => ({ + link: resolve_url(base_url, $('a', elem).attr('href')), + title: $('a', elem).text(), + pubDate: new Date( + $('a>span', elem) + .text() + .replace(/.(\d+)年(\d+)月(\d+)日./, '$1-$2-$3') + ).toUTCString(), + })) + .get(), + }; +};