feat: add 重庆大学校团委 (#4832)

This commit is contained in:
郭俊余
2020-05-22 00:22:10 +08:00
committed by GitHub
parent d7b826168c
commit 174cffb614
3 changed files with 72 additions and 0 deletions

View File

@@ -1774,6 +1774,16 @@ type 列表:
<Route author="nicolaszf" example="/cqu/news/jzyg" path="/cqu/news/jzyg"/>
### 校团委
<Route author="Hagb" example="/cqu/youth/gzdt" path="/cqu/youth/:category" :paramsDesc="['分类名']">
| 工作动态 | 院系风采 | 通知公告(可能需内网) | 文件转载 |
| -------- | -------- | ---------------------- | -------- |
| gzdt | yxfc | tzgg | wjzz |
</Route>
## 重庆科技学院
### 教务处公告

View File

@@ -661,6 +661,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('/nuist/bulletin/:category?', require('./routes/universities/nuist/bulletin'));

View File

@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category;
const baseUrl = 'http://youth.cqu.edu.cn/index/';
const url = `http://youth.cqu.edu.cn/index/${category}.htm`;
const response = await got({
method: 'get',
url: url,
});
const data = response.data;
const $ = cheerio.load(data);
const links = $('div[class=nwes_list]')
.find('ul[style]') // nwes_list 原文如此
.find('a[target=_blank]')
.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, authorText] = newsContent.find('div[align=center]').text().split(/\xA0+/, 2); // \xA0+: &nbsp;
item.pubDate = dateText.replace(/ /, 'T') + '+08:00';
if (authorText && authorText.slice(0, 4) === '拟稿人:') {
item.author = authorText.slice(4);
}
item.description = newsContent.find('div[class=v_news_content]').find('div').text();
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),
};
};