diff --git a/docs/university.md b/docs/university.md index 3ce4a9b73..3668953e4 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1923,6 +1923,10 @@ type 列表: +### 新闻网通知公告简报 + + + ### 校团委 diff --git a/lib/router.js b/lib/router.js index 732c355ba..06d8458d6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -680,6 +680,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/news/tz', require('./routes/universities/cqu/news/tz')); router.get('/cqu/youth/:category', require('./routes/universities/cqu/youth/info')); router.get('/cqu/sci/:category', require('./routes/universities/cqu/sci/info')); router.get('/cqu/net/:category', require('./routes/universities/cqu/net/info')); diff --git a/lib/routes/universities/cqu/news/tz.js b/lib/routes/universities/cqu/news/tz.js new file mode 100644 index 000000000..a8c0bd4c6 --- /dev/null +++ b/lib/routes/universities/cqu/news/tz.js @@ -0,0 +1,71 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + // const category = ctx.params.category; + + // const baseUrl = 'https://news.cqu.edu.cn/newsv2/'; + const url = 'https://news.cqu.edu.cn/newsv2/list-18.html'; + const response = await got({ + method: 'get', + url: url, + }); + + const data = response.data; + const $ = cheerio.load(data); + const nowDate = new Date(new Date().toLocaleString('en-US', { timeZone: 'Asia/Shanghai' })); + const links = $('div[class=lists]', 'div[class="container newslist"]') + .find('div[class="content w100"]', 'div[class="item"]') + .map((index, item) => { + item = $(item); + const a = item.find('a[href]'); + const dateText = item.find('div[class=rdate]').text().trim(); + const month = dateText.slice(0, 2); + const day = dateText.slice(2, 4); + const year = String((Number(month) === nowDate.getMonth() + 1 && Number(day) <= nowDate.getDate()) || Number(month) < nowDate.getMonth() + 1 ? nowDate.getFullYear() : nowDate.getFullYear() - 1); + return { + title: a.text(), + link: a.attr('href'), + pubDate: `${year}-${month}-${day}T00:00+08:00`, + }; + }) + .get(); + + const items = await Promise.all( + [...links].map(async ({ title, link, pubDate }) => { + const item = { + title: title, + link: link, + pubDate: pubDate, + }; + const cache = await ctx.cache.get(link); + if (cache) { + return JSON.parse(cache); + } + const response = await got({ + method: 'get', + url: link, + }); + const $ = cheerio.load(response.data); + const newsContent = $('div[class=content]', 'div[class="container detail"]'); + + item.description = newsContent.find('div[class=acontent]').html(); + + const authorStrings = newsContent + .find('p', 'div[class=dinfoa]') + .find('a[href="javascript:;"]') + .map((index, item) => $(item).text()); + item.author = `${authorStrings[0]}-${authorStrings[1]}`; + + 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), + }; +};