diff --git a/docs/README.md b/docs/README.md index ee0c3a558..d22d7fd0d 100755 --- a/docs/README.md +++ b/docs/README.md @@ -2044,6 +2044,16 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +### 浙江工商大学 + + + +| 通知公告 | 学生专区 | 公示公告 | +| -------- | -------- | -------- | +| tzgg | xszq | gsgg | + + + ## 传统媒体 ### 央视新闻 diff --git a/lib/router.js b/lib/router.js index faa8b9a12..6e9b52435 100755 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/universities/zjgsu/gsgg/scripts.js b/lib/routes/universities/zjgsu/gsgg/scripts.js new file mode 100644 index 000000000..ba8e1ff69 --- /dev/null +++ b/lib/routes/universities/zjgsu/gsgg/scripts.js @@ -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(), + }; +}; diff --git a/lib/routes/universities/zjgsu/tzgg/scripts.js b/lib/routes/universities/zjgsu/tzgg/scripts.js new file mode 100644 index 000000000..1e41be267 --- /dev/null +++ b/lib/routes/universities/zjgsu/tzgg/scripts.js @@ -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, + }; +}; diff --git a/lib/routes/universities/zjgsu/tzgg/utils.js b/lib/routes/universities/zjgsu/tzgg/utils.js new file mode 100644 index 000000000..34e0d074e --- /dev/null +++ b/lib/routes/universities/zjgsu/tzgg/utils.js @@ -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, +}; diff --git a/lib/routes/universities/zjgsu/xszq/scripts.js b/lib/routes/universities/zjgsu/xszq/scripts.js new file mode 100644 index 000000000..86df68b9a --- /dev/null +++ b/lib/routes/universities/zjgsu/xszq/scripts.js @@ -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(), + }; +};