Add 雪球用户动态订阅 close #140 (#434)

* Add 雪球用户动态订阅 close #140

* Add referer
This commit is contained in:
imlonghao 2018-08-08 17:33:32 +08:00 committed by DIYgod
parent 09c92b363e
commit 110719d89f
5 changed files with 129 additions and 0 deletions

View File

@ -205,6 +205,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 早报
- 维基百科
- 中国大陆新闻动态
- 雪球
- 用户动态
- 用户收藏动态
- 中国美术馆
- 通知公告
- Greasy Fork

View File

@ -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 中找到
## 中国美术馆
### 通知公告

View File

@ -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'));

41
routes/xueqiu/favorite.js Normal file
View File

@ -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}`,
})),
};
};

53
routes/xueqiu/user.js Normal file
View File

@ -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}`,
})),
};
};