diff --git a/docs/university.md b/docs/university.md index 7529292a3..7a29d7a45 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1774,6 +1774,16 @@ type 列表: +### 校团委 + + + +| 工作动态 | 院系风采 | 通知公告(可能需内网) | 文件转载 | +| -------- | -------- | ---------------------- | -------- | +| gzdt | yxfc | tzgg | wjzz | + + + ## 重庆科技学院 ### 教务处公告 diff --git a/lib/router.js b/lib/router.js index 0e4fdee8b..a782f3e73 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/universities/cqu/youth/info.js b/lib/routes/universities/cqu/youth/info.js new file mode 100644 index 000000000..876ae5bb8 --- /dev/null +++ b/lib/routes/universities/cqu/youth/info.js @@ -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+:   + + 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), + }; +};