add 广东海洋大学教务通知 (#1956)

更改:代码格式标准化
This commit is contained in:
Xiaotouming 2019-04-19 00:23:15 +08:00 committed by DIYgod
parent 64998cedaf
commit 1959a83b23
4 changed files with 113 additions and 4 deletions

View File

@ -607,10 +607,6 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
<Route name="数据科学与计算机学院动态" author="MegrezZhu" example="/sysu/sdcs" path="/sysu/sdcs" />
## 中国传媒大学
<Route name="中国传媒大学研究生招生网" author="YunYouJun" example="/cuc/yz" path="/cuc/yz" />
## 中国药科大学
<Route name="中国药科大学" author="kba977" example="/cpu/home" path="/cpu/:type" :paramsDesc="['分类, 见下表']">
@ -697,6 +693,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</Route>
## 中国传媒大学
<Route name="中国传媒大学研究生招生网" author="YunYouJun" example="/cuc/yz" path="/cuc/yz" />
## 北京科技大学天津学院
<Route name="北京科技大学天津学院" author="henbf" example="/ustb/tj/news/all" path="/universities/ustb/tj/news/:type" :paramsDesc="['默认为 `all`']">
@ -706,3 +706,7 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
| all | xyxw | xshhd | csjsxy | xxgcxy | jjx | glxy | clx | jxgcx | hlx | flx | wyx | ysx |
</Route>
## 广东海洋大学
<Route name="广东海洋大学" author="Xiaotouming" example="/gdoujwc" path="/gdoujwc"/>

View File

@ -1267,4 +1267,7 @@ router.get('/vocus/publication/:id', require('./routes/vocus/publication'));
router.get('/1point3acres/user/:id/threads', require('./routes/1point3acres/threads'));
router.get('/1point3acres/user/:id/posts', require('./routes/1point3acres/posts'));
// 广东海洋大学
router.get('/gdoujwc', require('./routes/universities/gdou/jwc/jwtz'));
module.exports = router;

View File

@ -0,0 +1,29 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const util = require('./utils');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: 'http://www3.gdou.edu.cn/jwc/',
responseType: 'arraybuffer',
});
// HTML-buffer转为gb2312
const data = iconv.decode(response.data, 'gb2312');
const $ = cheerio.load(data);
const list = $('.bor03.cont li')
.slice(0, 10)
.get();
const result = await util.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: $('title').text(),
link: 'http://www3.gdou.edu.cn/jwc/Item/list.asp?id=1224',
description: '教务通知',
item: result,
};
};

View File

@ -0,0 +1,73 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const iconv = require('iconv-lite');
// 专门定义一个function用于加载文章内容
async function load(link) {
// 异步请求文章
const response = await axios({
method: 'get',
url: link,
responseType: 'arraybuffer',
headers: {
Referer: 'http://www3.gdou.edu.cn/jwc/',
},
});
// 加载文章内容
// 先将HTML-buffer转为gb2312
const data = iconv.decode(response.data, 'gb2312');
const $ = cheerio.load(data);
// 解析日期
const date = new Date(
$('.info')
.text()
.match(/\d{4}\/\d{1,2}\/\d{1,2}/)
);
const timeZone = 8;
const serverOffset = date.getTimezoneOffset() / 60;
const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
// 提取内容
const description = $('.left01').html();
// 返回解析的结果
return { description, pubDate };
}
const ProcessFeed = async (list, caches) => {
const host = 'http://www3.gdou.edu.cn/';
// 使用 Promise.all() 进行 async 并发
return await Promise.all(
// 遍历每一篇文章
list.map(async (item) => {
const $ = cheerio.load(item);
const $title = $('a');
// 还原相对链接为绝对链接
const itemUrl = url.resolve(host, $title.attr('href'));
// 列表上提取到的信息
const single = {
title: $title.text(),
link: itemUrl,
author: '教务部',
guid: itemUrl,
};
// 使用tryGet方法从缓存获取内容。
// 当缓存中无法获取到链接内容的时候则使用load方法加载文章内容。
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
// 合并解析后的结果集作为该篇文章最终的输出结果
return Promise.resolve(Object.assign({}, single, other));
})
);
};
module.exports = {
ProcessFeed,
};