add feed for tj.ustb.edu.cn (#1859)

This commit is contained in:
Yu Zhang
2019-04-08 11:15:05 +08:00
committed by DIYgod
parent 0938b1a1e1
commit 54e3a7bb8d
3 changed files with 75 additions and 0 deletions

View File

@@ -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 |
</Route>
## 北京科技大学天津学院
<Route name="北京科技大学天津学院" author="henbf" example="/ustb/tj/news/all" path="/universities/ustb/tj/news/:type" :paramsDesc="['默认为 `all`']">
| 全部 | 学院新闻 | 学术活动 | 城市建设学院 | 信息工程学院 | 经济学院 | 管理学院 | 材料系 | 机械工程系 | 护理系 | 法律系 | 外语系 | 艺术系 |
| ---- | -------- | -------- | ------------ | ------------ | -------- | -------- | ------ | ---------- | ------ | ------ | ------ | ------ |
| all | xyxw | xshhd | csjsxy | xxgcxy | jjx | glxy | clx | jxgcx | hlx | flx | wyx | ysx |
</Route>

View File

@@ -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'));

View File

@@ -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;
};