feat: add 重庆大学数学与统计学院 (#4840)

This commit is contained in:
郭俊余 2020-05-22 16:21:56 +08:00 committed by GitHub
parent 48c1a86ede
commit 917b2dbc5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 0 deletions

View File

@ -1783,6 +1783,16 @@ type 列表:
</Route>
### 数学与统计学院
<Route author="Hagb" example="/cqu/sci/1053" path="/cqu/sci/:category" :paramsDesc="['分类名']">
| 学院新闻 | 学院公告 | 学院活动 | 学术活动 |
| -------- | -------- | -------- | -------- |
| 1053 | 1054 | 1055 | 1056 |
</Route>
## 重庆科技学院
### 教务处公告

View File

@ -662,6 +662,7 @@ router.get('/heu/job/:type?', require('./routes/universities/heu/job'));
router.get('/cqu/jwc/announcement', require('./routes/universities/cqu/jwc/announcement'));
router.get('/cqu/news/jzyg', require('./routes/universities/cqu/news/jzyg'));
router.get('/cqu/youth/:category', require('./routes/universities/cqu/youth/info'));
router.get('/cqu/sci/:category', require('./routes/universities/cqu/sci/info'));
// 南京信息工程大学
router.get('/nuist/bulletin/:category?', require('./routes/universities/nuist/bulletin'));

View File

@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category;
const baseUrl = 'http://sci.cqu.edu.cn/';
const url = `http://sci.cqu.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=${category}`;
const response = await got({
method: 'get',
url: url,
});
const data = response.data;
const $ = cheerio.load(data);
const links = $('div[class=subcontent]')
.find('a[target=_blank]', 'ul[class=subNewsList]')
.map((index, item) => ({
title: item.attribs.title,
link: baseUrl + item.attribs.href,
}))
.get();
const items = await Promise.all(
[...links].map(async ({ title, link }) => {
const item = {
title: title,
link: link,
};
const cache = await ctx.cache.get(link);
if (cache) {
return JSON.parse(cache);
}
const response = await got({
method: 'get',
url: link,
});
const newsContent = cheerio.load(response.data)('form[name=_newscontent_fromname]');
const [dateText] = newsContent.find('div[align=center]').text().split(/\xA0+/, 1); // \xA0+: &nbsp;
item.pubDate = dateText.replace(/ /, 'T') + '+08:00';
const newsText = newsContent.find('div[class=v_news_content]');
const attedText = newsText.parent().nextAll().filter('ul[style="list-style-type:none;"]');
item.description = newsText.html() + (newsContent.html(attedText).html() || '');
ctx.cache.set(item.link, JSON.stringify(item));
return Promise.resolve(item);
})
);
ctx.state.data = {
title: $('title').text(),
link: url,
description: $.title,
item: items.filter((x) => x),
};
};