From 7f511334e2b3f230f92adc98a94c0284889fae23 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Mon, 3 Oct 2022 06:04:14 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=9B=AA=E7=90=83?=
=?UTF-8?q?=E4=BB=8A=E6=97=A5=E8=AF=9D=E9=A2=98=20(#10984)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/finance.md | 4 +++
lib/v2/xueqiu/maintainer.js | 1 +
lib/v2/xueqiu/radar.js | 6 ++++
lib/v2/xueqiu/router.js | 1 +
lib/v2/xueqiu/today.js | 65 +++++++++++++++++++++++++++++++++++++
5 files changed, 77 insertions(+)
create mode 100644 lib/v2/xueqiu/today.js
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,
+ };
+};