diff --git a/docs/finance.md b/docs/finance.md index 7925dc4fb..8d9679eef 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -525,6 +525,10 @@ TokenInsight 官方亦有提供 RSS,可参考 + ### 用户动态 diff --git a/lib/v2/xueqiu/maintainer.js b/lib/v2/xueqiu/maintainer.js index 75be5e02c..dc4908349 100644 --- a/lib/v2/xueqiu/maintainer.js +++ b/lib/v2/xueqiu/maintainer.js @@ -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'], }; diff --git a/lib/v2/xueqiu/radar.js b/lib/v2/xueqiu/radar.js index 2b52a4d70..99f456db8 100644 --- a/lib/v2/xueqiu/radar.js +++ b/lib/v2/xueqiu/radar.js @@ -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', diff --git a/lib/v2/xueqiu/router.js b/lib/v2/xueqiu/router.js index 963ac5b4f..e266cad05 100644 --- a/lib/v2/xueqiu/router.js +++ b/lib/v2/xueqiu/router.js @@ -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')); }; diff --git a/lib/v2/xueqiu/today.js b/lib/v2/xueqiu/today.js new file mode 100644 index 000000000..570921af1 --- /dev/null +++ b/lib/v2/xueqiu/today.js @@ -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, + }; +};