From ed7f05464a888d7a7283d2ec0de7c9fd892faac9 Mon Sep 17 00:00:00 2001 From: niayyy <44686955+niayyy-S@users.noreply.github.com> Date: Thu, 19 Dec 2019 17:22:12 +0800 Subject: [PATCH] feat: add zzu news and fix doc error (#3597) --- docs/joinus/README.md | 2 +- docs/university.md | 22 ++++++ lib/router.js | 4 ++ lib/routes/universities/zzu/news.js | 90 ++++++++++++++++++++++++ lib/routes/universities/zzu/soft/news.js | 78 ++++++++++++++++++++ 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 lib/routes/universities/zzu/news.js create mode 100644 lib/routes/universities/zzu/soft/news.js diff --git a/docs/joinus/README.md b/docs/joinus/README.md index 38d922b18..8e62ac4e9 100644 --- a/docs/joinus/README.md +++ b/docs/joinus/README.md @@ -276,7 +276,7 @@ sidebar: auto 4. **使用通用配置型路由** 很大一部分网站是可以通过一个配置范式来生成 RSS 的。 - 通用配置即通过 cherrio(**CSS 选择器、jQuery 函数**)读取 json 数据来简便的生成 RSS。 + 通用配置即通过 cheerio(**CSS 选择器、jQuery 函数**)读取 json 数据来简便的生成 RSS。 首先我们需要几个数据: diff --git a/docs/university.md b/docs/university.md index dcb5e5326..bd456f846 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1047,6 +1047,28 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 郑州大学 + +### 郑州大学新闻网 + + + +| 参数名称 | 综合新闻 | 学术动态 | 媒体郑大 | 院系风采 | 教学科研 | 学生信息 | 外事信息 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| 参数 | zh | xs | mt | yx | ky | stu | ws | + + + +### 软件学院 + + + +| 参数名称 | 学院新闻 | 学院公告 | 学生工作 | +| -------- | -------- | -------- | -------- | +| 参数 | xyxw | xygg | xsgz | + + + ## 中国传媒大学 ### 中国传媒大学研究生招生网 diff --git a/lib/router.js b/lib/router.js index 2f21208e0..cc9e2de39 100644 --- a/lib/router.js +++ b/lib/router.js @@ -627,6 +627,10 @@ router.get('/nuist/cas/:category?', require('./routes/universities/nuist/cas')); // 成都信息工程大学 router.get('/cuit/cxxww/:type?', require('./routes/universities/cuit/cxxww')); +// 郑州大学 +router.get('/zzu/news/:type', require('./routes/universities/zzu/news')); +router.get('/zzu/soft/news/:type', require('./routes/universities/zzu/soft/news')); + // 重庆科技学院 router.get('/cqust/jw/:type?', require('./routes/universities/cqust/jw')); router.get('/cqust/lib/:type?', require('./routes/universities/cqust/lib')); diff --git a/lib/routes/universities/zzu/news.js b/lib/routes/universities/zzu/news.js new file mode 100644 index 000000000..656ae1873 --- /dev/null +++ b/lib/routes/universities/zzu/news.js @@ -0,0 +1,90 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + xs: { + title: '学术动态', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=205', + }, + mt: { + title: '媒体郑大', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=208', + }, + zh: { + title: '综合新闻', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=202', + }, + yx: { + title: '院系风采', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=206', + }, + ky: { + title: '教学科研', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=203', + }, + stu: { + title: '学生信息', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=204', + }, + ws: { + title: '外事信息', + url: 'http://www16.zzu.edu.cn/msgs/vmsgisapi.dll/vmsglist?mtype=x&lan=209', + }, +}; +async function getNewsDetail(link) { + const res = await got.get(link); + const $ = cheerio.load(res.data); + return { + author: $('.zzj_4 .zzj_f2') + .eq(1) + .text(), + pubDate: new Date( + $('.zzj_4 .zzj_f2') + .eq(2) + .text() + ).toUTCString(), + description: $('.zzj_5').html(), + }; +} + +module.exports = async (ctx) => { + const type = ctx.params.type || 'zh'; + const url = config[type].url; + const title = config[type].title; + + const res = await got.get(url); + const $ = cheerio.load(res.data); + + const out = await Promise.all( + $('.zzj_5 .zzj_5a') + .slice(0, 10) + .map(async (i, v) => { + const link = $(v) + .find('a') + .attr('href'); + const title = $(v) + .find('.zzj_f6_c') + .text(); + const single = { + title, + link, + }; + let other = {}; + const cache = await ctx.cache.get(link); + if (cache) { + other = JSON.parse(cache); + } else { + other = await getNewsDetail(link); + ctx.cache.set(link, JSON.stringify(other)); + } + + return Promise.resolve(Object.assign({}, single, other)); + }) + .get() + ); + ctx.state.data = { + title: `郑州大学新闻网 -- ${title}`, + link: 'http://news.zzu.edu.cn/', + item: out, + }; +}; diff --git a/lib/routes/universities/zzu/soft/news.js b/lib/routes/universities/zzu/soft/news.js new file mode 100644 index 000000000..c0aa77082 --- /dev/null +++ b/lib/routes/universities/zzu/soft/news.js @@ -0,0 +1,78 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + xyxw: { + title: '学院新闻', + url: 'http://www5.zzu.edu.cn/soft/xyxw.htm', + }, + + xygg: { + title: '学院公告', + url: 'http://www5.zzu.edu.cn/soft/xygg.htm', + }, + + xsgz: { + title: '学生工作', + url: 'http://www5.zzu.edu.cn/soft/xsgz.htm', + }, +}; +async function getNewsDetail(link) { + const res = await got.get(link); + const $ = cheerio.load(res.data); + return { + author: '软件学院', + description: $('.article_content').html(), + }; +} + +module.exports = async (ctx) => { + const type = ctx.params.type || 'xyxw'; + const url = config[type].url; + const title = config[type].title; + const BaseURL = 'http://www5.zzu.edu.cn/soft/'; + + const res = await got.get(url); + const $ = cheerio.load(res.data); + + const out = await Promise.all( + $('.list .span8') + .slice(0, 10) + .map(async (i, v) => { + const link = + BaseURL + + $(v) + .find('a') + .attr('href'); + const title = $(v) + .find('a') + .text(); + const pubDate = new Date( + $(v) + .find('.fr') + .text() + ).toUTCString(); + const single = { + link, + title, + pubDate, + }; + let other = {}; + const cache = await ctx.cache.get(link); + if (cache) { + other = JSON.parse(cache); + } else { + other = await getNewsDetail(link); + ctx.cache.set(link, JSON.stringify(other)); + } + + return Promise.resolve(Object.assign({}, single, other)); + }) + .get() + ); + ctx.state.data = { + title: `郑州大学软件学院 -- ${title}`, + link: 'http://www5.zzu.edu.cn/soft/index.htm', + item: out, + }; +};