From 8b9060bec0465ac7f1ec2af7721941bf3a228f7f Mon Sep 17 00:00:00 2001 From: hillerliao Date: Mon, 8 Oct 2018 11:08:43 +0800 Subject: [PATCH] monitor xueqiu user's stock (#839) monitor xueqiu user's stock in rss format --- docs/README.md | 2 ++ router.js | 1 + routes/xueqiu/user_stock.js | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 routes/xueqiu/user_stock.js diff --git a/docs/README.md b/docs/README.md index fd4c3affc..f9547926b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -494,6 +494,8 @@ RSSHub 提供下列 API 接口: + + ## 编程 diff --git a/router.js b/router.js index ddd539e5d..dd5cdeba7 100644 --- a/router.js +++ b/router.js @@ -400,6 +400,7 @@ router.get('/wikipedia/mainland', require('./routes/wikipedia/mainland')); // 雪球 router.get('/xueqiu/user/:id/:type?', require('./routes/xueqiu/user')); router.get('/xueqiu/favorite/:id', require('./routes/xueqiu/favorite')); +router.get('/xueqiu/user_stock/:id', require('./routes/xueqiu/user_stock')); router.get('/xueqiu/fund/:id', require('./routes/xueqiu/fund')); // Greasy Fork diff --git a/routes/xueqiu/user_stock.js b/routes/xueqiu/user_stock.js new file mode 100644 index 000000000..1e2991f8c --- /dev/null +++ b/routes/xueqiu/user_stock.js @@ -0,0 +1,49 @@ +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const res1 = await axios({ + method: 'get', + url: 'https://xueqiu.com/', + }); + const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0]; + + const res2 = await axios({ + method: 'get', + url: 'https://xueqiu.com/v4/stock/portfolio/stocks.json?size=10000&type=1&pid=-1&category=2', + params: { + uid: id, + }, + headers: { + Cookie: token, + Referer: `https://xueqiu.com/u/${id}`, + }, + }); + const data = res2.data.stocks; + + const res3 = await axios({ + method: 'get', + url: 'https://xueqiu.com/statuses/original/show.json', + params: { + user_id: id, + }, + headers: { + Cookie: token, + Referer: `https://xueqiu.com/u/${id}`, + }, + }); + const screen_name = res3.data.user.screen_name; + + ctx.state.data = { + title: `${screen_name} 的雪球自选动态`, + link: `https://xueqiu.com/u/${id}`, + description: `@${screen_name} 的雪球自选动态`, + item: data.map((item) => ({ + title: `@${screen_name} 关注了股票 ${item.stockName}`, + description: `@${screen_name} 在${new Date(item.createAt).toLocaleString()} 关注了 ${item.stockName}(${item.exchange}:${item.code})。`, + pubDate: new Date(item.createAt).toUTCString(), + link: `https://xueqiu.com/s/${item.code}`, + })), + }; +};