feat: add 重庆大学新闻网通知公告简报 (#5403)
This commit is contained in:
parent
29fe03c48c
commit
809c4364ff
|
|
@ -1923,6 +1923,10 @@ type 列表:
|
|||
|
||||
<Route author="nicolaszf" example="/cqu/news/jzyg" path="/cqu/news/jzyg"/>
|
||||
|
||||
### 新闻网通知公告简报
|
||||
|
||||
<Route author="Hagb" example="/cqu/news/tz" path="/cqu/news/tz"/>
|
||||
|
||||
### 校团委
|
||||
|
||||
<Route author="Hagb" example="/cqu/youth/gzdt" path="/cqu/youth/:category" :paramsDesc="['分类名']">
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue