feat: add cgtn opinions

This commit is contained in:
nczitzk 2021-01-09 22:33:00 +08:00
parent b1ae777b87
commit f8da7ce835
4 changed files with 60 additions and 0 deletions

View File

@ -67,6 +67,10 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
## CGTN
### Opinions
<RouteEn author="nczitzk" example="/cgtn/opinions" path="/cgtn/opinions"/>
### Most Read & Most Share
<RouteEn author="nczitzk" example="/cgtn/most/read/day" path="/cgtn/most/:type?/:time?" :paramsDesc="['Type, `read` as most read, `share` as most share, `read` by default', 'Time range, `all` as all the time, `day` as today, `week` as this week, `month` as this month, `year` as this year, `all` by default']"/>

View File

@ -122,6 +122,10 @@ pageClass: routes
## CGTN
### Opinions
<Route author="nczitzk" example="/cgtn/opinions" path="/cgtn/opinions"/>
### Most Read & Most Share
<Route author="nczitzk" example="/cgtn/most/read/day" path="/cgtn/most/:type?/:time?" :paramsDesc="['类型,`read` 指最多阅读,`share` 指最多分享,默认为 `read`', '时间,`all` 指所有时间,`day` 指今天,`week` 指本周,`month` 指本月,`year` 指今年,默认为 `all`']"/>

View File

@ -3338,6 +3338,7 @@ router.get('/fulinian/:caty?', require('./routes/fulinian/index'));
// CGTN
router.get('/cgtn/most/:type?/:time?', require('./routes/cgtn/most'));
router.get('/cgtn/opinions', require('./routes/cgtn/opinions'));
// AppSales
router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));

View File

@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = `https://www.cgtn.com/opinions`;
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
$('.cg-pic').parent().remove();
const list = $(`.cg-title h4`)
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: a.attr('href'),
pubDate: new Date(parseInt(a.attr('data-time'))).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.author = content('.news-author-name').text();
item.description = content('#cmsMainContent').html();
return item;
})
)
);
ctx.state.data = {
title: 'CGTN - Opinions',
link: rootUrl,
item: items,
};
};