From 110719d89ff0f97c2a34140536ad3f515bd1eaaa Mon Sep 17 00:00:00 2001 From: imlonghao Date: Wed, 8 Aug 2018 17:33:32 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E9=9B=AA=E7=90=83=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=AE=A2=E9=98=85=20close=20#140=20(#434)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add 雪球用户动态订阅 close #140 * Add referer --- README.md | 3 +++ docs/README.md | 28 +++++++++++++++++++++ router.js | 4 +++ routes/xueqiu/favorite.js | 41 ++++++++++++++++++++++++++++++ routes/xueqiu/user.js | 53 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 routes/xueqiu/favorite.js create mode 100644 routes/xueqiu/user.js diff --git a/README.md b/README.md index 459dd264f..e026d96e4 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 早报 - 维基百科 - 中国大陆新闻动态 +- 雪球 + - 用户动态 + - 用户收藏动态 - 中国美术馆 - 通知公告 - Greasy Fork diff --git a/docs/README.md b/docs/README.md index e90fe4b26..711cb5eda 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1657,6 +1657,34 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 参数:无 +## 雪球 + +### 用户动态 + +举例: [https://rsshub.app/xueqiu/user/8152922548](https://rsshub.app/xueqiu/user/8152922548) + +路由: `/xueqiu/user/:id/:type?` + +参数: + +id,用户 id,可在用户主页 URL 中找到 + +type,可选,动态的类型,不填则默认全部 + +| 原发布 | 长文 | 问答 | 热门 | 交易 | +| ------ | ---- | ---- | ---- | ---- | +| 0 | 2 | 4 | 9 | 11 | + +### 用户收藏动态 + +举例: [https://rsshub.app/xueqiu/favorite/8152922548](https://rsshub.app/xueqiu/favorite/8152922548) + +路由: `/xueqiu/favorite/:id` + +参数: + +id,用户 id,可在用户主页 URL 中找到 + ## 中国美术馆 ### 通知公告 diff --git a/router.js b/router.js index 5ddb5b66b..bbd1f472c 100755 --- a/router.js +++ b/router.js @@ -382,6 +382,10 @@ router.get('/dongqiudi/daily', require('./routes/dongqiudi/index')); // 维基百科 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')); + // Greasy Fork router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts')); diff --git a/routes/xueqiu/favorite.js b/routes/xueqiu/favorite.js new file mode 100644 index 000000000..b9970fa93 --- /dev/null +++ b/routes/xueqiu/favorite.js @@ -0,0 +1,41 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const res1 = await axios({ + method: 'get', + url: 'https://xueqiu.com/', + header: { + 'User-Agent': config.ua, + }, + }); + 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/favorites.json', + params: { + userid: id, + }, + headers: { + 'User-Agent': config.ua, + Cookie: token, + Referer: `https://xueqiu.com/u/${id}`, + }, + }); + const data = res2.data.list; + + ctx.state.data = { + title: `ID: ${id} 的雪球收藏动态`, + link: `https://xueqiu.com/u/${id}`, + description: `ID: ${id} 的雪球收藏动态`, + item: data.map((item) => ({ + title: item.title, + description: item.description, + pubDate: new Date(item.created_at).toUTCString(), + link: `https://xueqiu.com${item.target}`, + })), + }; +}; diff --git a/routes/xueqiu/user.js b/routes/xueqiu/user.js new file mode 100644 index 000000000..74a5625c1 --- /dev/null +++ b/routes/xueqiu/user.js @@ -0,0 +1,53 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const type = ctx.params.type || 10; + const source = type === '11' ? '买卖' : ''; + const typename = { + 10: '全部', + 0: '原发布', + 2: '长文', + 4: '问答', + 9: '热门', + 11: '交易', + }; + + const res1 = await axios({ + method: 'get', + url: 'https://xueqiu.com/', + header: { + 'User-Agent': config.ua, + }, + }); + 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/statuses/user_timeline.json', + params: { + user_id: id, + type: type, + source: source, + }, + headers: { + 'User-Agent': config.ua, + Cookie: token, + Referer: `https://xueqiu.com/u/${id}`, + }, + }); + const data = res2.data.statuses.filter((s) => s.mark !== 1); // 去除置顶动态 + + ctx.state.data = { + title: `${data[0].user.screen_name} 的雪球${typename[type]}动态`, + link: `https://xueqiu.com/u/${id}`, + description: `${data[0].user.screen_name} 的雪球${typename[type]}动态`, + item: data.map((item) => ({ + title: item.title, + description: item.description, + pubDate: new Date(item.created_at).toUTCString(), + link: `https://xueqiu.com${item.target}`, + })), + }; +};