diff --git a/docs/university.md b/docs/university.md index 8a0a2fd760..f692315752 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1152,6 +1152,28 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 扬州大学 + +### 官网消息 + + + +| 学校要闻 | 校园新闻 | 信息公告 | 学术活动 | 媒体扬大 | +| -------- | -------- | -------- | -------- | -------- | +| xxyw | xyxw | xxgg | xshd | mtyd | + + + +### 研究生招生 + + + +| 通知公告 | 博士招生 | 硕士招生 | +| -------- | -------- | -------- | +| tzgg | bszs | sszs | + + + ## 浙江大学 ### 普通栏目 如学术/图片/新闻等 diff --git a/lib/router.js b/lib/router.js index 3fc9227c60..8cdacad4e4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2316,4 +2316,8 @@ router.get('/blogs/hedwig/:type', require('./routes/blogs/hedwig')); // LoveHeaven router.get('/loveheaven/update/:slug', require('./routes/loveheaven/update')); +// 扬州大学 +router.get('/yzu/home/:type', require('./routes/universities/yzu/home')); +router.get('/yzu/yjszs/:type', require('./routes/universities/yzu/yjszs')); + module.exports = router; diff --git a/lib/routes/universities/yzu/home.js b/lib/routes/universities/yzu/home.js new file mode 100644 index 0000000000..977812d6dc --- /dev/null +++ b/lib/routes/universities/yzu/home.js @@ -0,0 +1,83 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'http://www.yzu.edu.cn/'; + +const map = new Map([ + ['xxyw', { title: '扬州大学 -- 学校要闻', suffix: 'col/col37745/index.html', id: 37745 }], + ['xyxw', { title: '扬州大学 -- 校园新闻', suffix: 'col/col37746/index.html', id: 37746 }], + ['xxgg', { title: '扬州大学 -- 信息公告', suffix: 'col/col37747/index.html', id: 37747 }], + ['xshd', { title: '扬州大学 -- 学术活动', suffix: 'col/col37748/index.html', id: 37748 }], + ['mtyd', { title: '扬州大学 -- 媒体扬大', suffix: 'col/col45661/index.html', id: 45661 }], +]); + +module.exports = async (ctx) => { + const type = ctx.params.type; + const suffix = map.get(type).suffix; + + const link = url.resolve(host, suffix); + const response = await got({ + method: 'post', + url: 'http://www.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + Accept: 'application/xml', + }, + data: `columnid=${map.get(type).id}&unitid=54996`, + }); + const $ = cheerio.load(response.data, { xmlMode: true }); + + const list = $('record') + .slice(0, 10) + .map(function() { + const $$ = cheerio.load($(this).html()); + const info = { + title: $$('a').attr('title'), + link: $$('a').attr('href'), + date: $$('span').text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + let description; + if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) { + const response = await got.get(itemUrl); + const $ = cheerio.load(response.data); + description = $('#zoom') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`) + .trim(); + } else { + description = '站外链接无法抓取全文'; + } + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: map.get(type).title, + link: link, + description: '扬州大学 RSS', + item: out, + }; +}; diff --git a/lib/routes/universities/yzu/yjszs.js b/lib/routes/universities/yzu/yjszs.js new file mode 100644 index 0000000000..23c95e4e06 --- /dev/null +++ b/lib/routes/universities/yzu/yjszs.js @@ -0,0 +1,81 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'http://yjszs.yzu.edu.cn/'; + +const map = new Map([ + ['tzgg', { title: '扬州大学研究生招生 -- 通知公告', suffix: 'col/col37091/index.html', id: 37091 }], + ['bszs', { title: '扬州大学研究生招生 -- 博士招生', suffix: 'col/col37129/index.html', id: 37129 }], + ['sszs', { title: '扬州大学研究生招生 -- 硕士招生', suffix: 'col/col37130/index.html', id: 37130 }], +]); + +module.exports = async (ctx) => { + const type = ctx.params.type; + const suffix = map.get(type).suffix; + + const link = url.resolve(host, suffix); + const response = await got({ + method: 'post', + url: 'http://yjszs.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + Accept: 'application/xml', + }, + data: `columnid=${map.get(type).id}&unitid=54996`, + }); + const $ = cheerio.load(response.data, { xmlMode: true }); + + const list = $('record') + .slice(0, 10) + .map(function() { + const $$ = cheerio.load($(this).html()); + const info = { + title: $$('a').attr('title'), + link: $$('a').attr('href'), + date: $$('span').text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + let description; + if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) { + const response = await got.get(itemUrl); + const $ = cheerio.load(response.data); + description = $('#zoom') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`) + .trim(); + } else { + description = '站外链接无法抓取全文'; + } + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: map.get(type).title, + link: link, + description: '扬州大学研究生招生 RSS', + item: out, + }; +};