diff --git a/docs/university.md b/docs/university.md index 6b41bcec1..3442e4f21 100644 --- a/docs/university.md +++ b/docs/university.md @@ -678,3 +678,13 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | + +## 北京科技大学天津学院 + + + +| 全部 | 学院新闻 | 学术活动 | 城市建设学院 | 信息工程学院 | 经济学院 | 管理学院 | 材料系 | 机械工程系 | 护理系 | 法律系 | 外语系 | 艺术系 | +| ---- | -------- | -------- | ------------ | ------------ | -------- | -------- | ------ | ---------- | ------ | ------ | ------ | ------ | +| all | xyxw | xshhd | csjsxy | xxgcxy | jjx | glxy | clx | jxgcx | hlx | flx | wyx | ysx | + + diff --git a/lib/router.js b/lib/router.js index 1c010bb5d..cbce3b730 100755 --- a/lib/router.js +++ b/lib/router.js @@ -726,6 +726,9 @@ router.get('/buaa/news/:type', require('./routes/universities/buaa/news/index')) // 上海大学 router.get('/shu/jwc/:type?', require('./routes/universities/shu/jwc')); +// 北京科技大学天津学院 +router.get('/ustb/tj/news/:type?', require('./routes/universities/ustb/tj/news')); + // ifanr router.get('/ifanr/:channel?', require('./routes/ifanr/index')); diff --git a/lib/routes/universities/ustb/tj/news.js b/lib/routes/universities/ustb/tj/news.js new file mode 100644 index 000000000..c80fd78e4 --- /dev/null +++ b/lib/routes/universities/ustb/tj/news.js @@ -0,0 +1,62 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const dayjs = require('dayjs'); +const _ = require('lodash'); + +const baseUrl = 'http://tj.ustb.edu.cn'; +const maps = { + xyxw: '/Class/xyxw/index.htm', + xshhd: '/Class/xshhd/index.htm', + csjsxy: '/Class/csjsxy/index.htm', + xxgcxy: '/Class/xxgcxy/index.htm', + jjx: '/Class/jjx/index.htm', + glxy: '/Class/glxy/index.htm', + clx: '/Class/clx/index.htm', + jxgcx: '/Class/jxgcx/index.htm', + hlx: '/Class/hlx/index.htm', + flx: '/Class/flx/index.htm', + wyx: '/Class/wyx/index.htm', + ysx: '/Class/ysx/index.htm', +}; + +function getNews(data) { + const $ = cheerio.load(data); + return $('div[class="classnews"] ul li a') + .slice(0, 5) + .map((_, elem) => ({ + link: baseUrl + elem.attribs.href, + title: elem.children[0].data, + pubDate: dayjs(elem.attribs.href.split('/')[3].split('.')[0]).toString(), + })) + .get(); +} + +module.exports = async (ctx) => { + let type = ctx.params.type || 'all'; + if (!_.includes(_.keys(maps), type)) { + type = 'all'; + } + + const responseData = { + title: '北京科技大学天津学院新闻动态', + link: baseUrl, + item: null, + }; + + if (type === 'all') { + const all = await Promise.all( + Object.values(maps).map(async (link) => { + const response = await axios.get(baseUrl + link); + const news = getNews(response.data); + return Promise.resolve(news); + }) + ); + responseData.item = _.orderBy(_.flatMapDepth(all), (res) => new Date(res.pubDate), ['desc']); + } else { + const response = await axios.get(baseUrl + maps[type]); + const news = getNews(response.data); + responseData.item = news; + } + + ctx.state.data = responseData; +};