添加浙江工商大学教务处和学校首页通知 (#1768)

close #1550
This commit is contained in:
nicolaszf
2019-03-18 02:11:49 -05:00
committed by DIYgod
parent c81c7469a3
commit 7858ee15d8
6 changed files with 176 additions and 0 deletions

View File

@@ -2044,6 +2044,16 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</route>
### 浙江工商大学
<route name="浙江工商大学" author="nicolaszf" example="/zjgsu/tzgg" path="/zjgsu/:type" :paramsDesc="['分类, 见下表']">
| 通知公告 | 学生专区 | 公示公告 |
| -------- | -------- | -------- |
| tzgg | xszq | gsgg |
</route>
## 传统媒体
### 央视新闻

View File

@@ -1163,4 +1163,9 @@ router.get('/vgtime/release', require('./routes/vgtime/release'));
// MP4吧
router.get('/mp4ba/:param', require('./routes/mp4ba'));
// 浙江工商大学
router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts'));
router.get('/zjgsu/gsgg', require('./routes/universities/zjgsu/gsgg/scripts'));
router.get('/zjgsu/xszq', require('./routes/universities/zjgsu/xszq/scripts'));
module.exports = router;

View File

@@ -0,0 +1,42 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const res = await axios({
method: 'get',
url: 'http://jww.zjgsu.edu.cn/ArticleList.asp?nid=83',
responseType: 'arraybuffer',
});
res.data = iconv.decode(res.data, 'gb2312');
const $ = cheerio.load(res.data);
const list = $('table')
.eq(19)
.find('tr');
ctx.state.data = {
title: '浙江工商大学教务处-公示公告',
link: 'http://jww.zjgsu.edu.cn/ArticleList.asp?nid=83',
description: '浙江工商大学教务处-公示公告',
item:
list &&
list
.map((index, item) => {
item = $(item);
const date = new Date(
item
.find('td')
.eq(2)
.text()
);
const serverOffset = date.getTimezoneOffset() / 60;
return {
title: item.find('a').text(),
description: item.find('a').text(),
link: `http://jww.zjgsu.edu.cn/${item.find('a').attr('href')}`,
pubDate: new Date(date.getTime() - 60 * 60 * 1000 * serverOffset).toUTCString(),
};
})
.get(),
};
};

View File

@@ -0,0 +1,23 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const util = require('./utils');
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: 'http://news.zjgsu.edu.cn/18/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('ul.list-1 li').get();
const result = await util.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: '浙江工商大学新闻网-通知公告',
link: 'http://news.zjgsu.edu.cn/18/',
description: '浙江工商大学新闻网-通知公告',
item: result,
};
};

View File

@@ -0,0 +1,54 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
// 加载文章页
async function load(link) {
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const date = new Date(
$('p')
.text()
.match(/\d{4}-\d{2}-\d{2}/)
);
const pubDate = new Date(date.getTime()).toUTCString();
// 提取内容
const description = $('dd').html();
return { description, pubDate };
}
const ProcessFeed = async (list, caches) => {
const host = 'http://news.zjgsu.edu.cn';
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,
guid: itemUrl,
};
// 使用tryGet方法从缓存获取内容。
// 当缓存中无法获取到链接内容的时候则使用load方法加载文章内容。
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
// 合并解析后的结果集作为该篇文章最终的输出结果
return Promise.resolve(Object.assign({}, single, other));
})
);
};
module.exports = {
ProcessFeed,
};

View File

@@ -0,0 +1,42 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const res = await axios({
method: 'get',
url: 'http://jww.zjgsu.edu.cn/ArticleList.asp?nid=6',
responseType: 'arraybuffer',
});
res.data = iconv.decode(res.data, 'gb2312');
const $ = cheerio.load(res.data);
const list = $('table')
.eq(20)
.find('tr');
ctx.state.data = {
title: '浙江工商大学教务处-学生专区',
link: 'http://jww.zjgsu.edu.cn/ArticleList.asp?nid=6',
description: '浙江工商大学教务处-学生专区',
item:
list &&
list
.map((index, item) => {
item = $(item);
const date = new Date(
item
.find('td')
.eq(2)
.text()
);
const serverOffset = date.getTimezoneOffset() / 60;
return {
title: item.find('a').text(),
description: item.find('a').text(),
link: `http://jww.zjgsu.edu.cn/${item.find('a').attr('href')}`,
pubDate: new Date(date.getTime() - 60 * 60 * 1000 * serverOffset).toUTCString(),
};
})
.get(),
};
};