feat(route): caijing (#11439)

This commit is contained in:
Tony 2022-12-12 15:24:46 -04:00 committed by GitHub
parent f9619615c2
commit 21115de374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 0 deletions

View File

@ -208,6 +208,12 @@ TokenInsight 官方亦有提供 RSS可参考 <https://api.tokeninsight.com/re
</Route>
## 财经网
### 滚动新闻
<Route author="TonyRL" example="/caijing/roll" path="/caijing/roll" rardr="1" rssbud="1"/>
## 财联社
### 电报

View File

@ -0,0 +1,3 @@
module.exports = {
'/roll': ['TonyRL'],
};

13
lib/v2/caijing/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'caijing.com.cn': {
_name: '财经网',
roll: [
{
title: '滚动新闻',
docs: 'https://docs.rsshub.app/finance.html#cai-jing-wang',
source: ['/index1.html', '/'],
target: '/caijing/roll',
},
],
},
};

46
lib/v2/caijing/roll.js Normal file
View File

@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const baseUrl = 'https://roll.caijing.com.cn';
const response = await got(`${baseUrl}/ajax_lists.php`, {
searchParams: {
modelid: 0,
time: Math.random(),
},
});
const list = response.data.map((item) => ({
title: item.title,
link: item.url.replace('http://', 'https://'),
pubDate: timezone(parseDate(item.published, 'MM-DD HH:mm'), +8),
category: item.cat,
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
item.author = $('.editor').text().trim() || $('#editor_baidu').text().trim().replace(/[()]/g, '');
item.description = $('.article-content').html();
item.category = [
item.category,
...$('.news_keywords span')
.toArray()
.map((e) => $(e).text()),
];
return item;
})
)
);
ctx.state.data = {
title: '滚动新闻-财经网',
image: 'https://www.caijing.com.cn/favicon.ico',
link: response.url,
item: items,
};
};

3
lib/v2/caijing/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/roll', require('./roll'));
};