feat(route): add 雪球今日话题 (#10984)
This commit is contained in:
@@ -525,6 +525,10 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re
|
||||
|
||||
## 雪球
|
||||
|
||||
### 今日话题
|
||||
|
||||
<Route author="nczitzk" example="/xueqiu/today" path="/xueqiu/today"/>
|
||||
|
||||
### 用户动态
|
||||
|
||||
<Route author="imlonghao" example="/xueqiu/user/8152922548" path="/xueqiu/user/:id/:type?" :paramsDesc="['用户 id, 可在用户主页 URL 中找到', '动态的类型, 不填则默认全部']">
|
||||
|
||||
@@ -6,6 +6,7 @@ module.exports = {
|
||||
'/snb/:id': ['ZhishanZhang'],
|
||||
'/stock_comments/:id/:titleLength?': ['zytomorrow'],
|
||||
'/stock_info/:id/:type?': ['YuYang'],
|
||||
'/today': ['nczitzk'],
|
||||
'/user/:id/:type?': ['imlonghao'],
|
||||
'/user_stock/:id': ['hillerliao'],
|
||||
};
|
||||
|
||||
@@ -13,6 +13,12 @@ module.exports = {
|
||||
'xueqiu.com': {
|
||||
_name: '雪球',
|
||||
'.': [
|
||||
{
|
||||
title: '今日话题',
|
||||
docs: 'https://docs.rsshub.app/finance.html#xue-qiu',
|
||||
source: ['/today'],
|
||||
target: '/xueqiu/today',
|
||||
},
|
||||
{
|
||||
title: '用户动态',
|
||||
docs: 'https://docs.rsshub.app/finance.html#xue-qiu',
|
||||
|
||||
@@ -6,6 +6,7 @@ module.exports = (router) => {
|
||||
router.get('/snb/:id', require('./snb'));
|
||||
router.get('/stock_comments/:id/:titleLength?', require('./stock_comments'));
|
||||
router.get('/stock_info/:id/:type?', require('./stock_info'));
|
||||
router.get('/today', require('./today'));
|
||||
router.get('/user/:id/:type?', require('./user'));
|
||||
router.get('/user_stock/:id', require('./user_stock'));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const size = ctx.query.limit ?? '20';
|
||||
|
||||
const rootUrl = 'https://xueqiu.com';
|
||||
const currentUrl = `${rootUrl}/today`;
|
||||
const apiUrl = `${rootUrl}/statuses/hot/listV2.json?since_id=-1&size=${size}`;
|
||||
|
||||
const firstResponse = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
const token = firstResponse.headers['set-cookie'].join(',').match(/(xq_a_token=.*?;)/)[1];
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
headers: {
|
||||
Referer: rootUrl,
|
||||
Cookie: token,
|
||||
},
|
||||
});
|
||||
|
||||
let items = response.data.items.map((item) => {
|
||||
item = item.original_status;
|
||||
|
||||
return {
|
||||
title: item.title || item.rawTitle || item.description.replace(/<(.*?)>/g, ''),
|
||||
link: `${rootUrl}${item.target}`,
|
||||
pubDate: parseDate(item.created_at),
|
||||
author: item.user.screen_name,
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
headers: {
|
||||
Referer: rootUrl,
|
||||
Cookie: token,
|
||||
},
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.article__bd__detail').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '今日话题 - 雪球',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user