增加 雪球基金净值更新 (#828)
This commit is contained in:
parent
5cf076a830
commit
76b4feb92b
|
|
@ -494,6 +494,8 @@ RSSHub 提供下列 API 接口:
|
|||
|
||||
<route name="用户收藏动态" author="imlonghao" example="/xueqiu/favorite/8152922548" path="/xueqiu/favorite/:id" :paramsDesc="['用户 id, 可在用户主页 URL 中找到']"/>
|
||||
|
||||
<route name="基金净值更新" author="HenryQW" example="/xueqiu/fund/040008" path="/xueqiu/fund/:id" :paramsDesc="['基金代码, 可在基金主页 URL 中找到. 此路由的数据为场外基金 (`F`开头)']"/>
|
||||
|
||||
## 编程
|
||||
|
||||
### 掘金
|
||||
|
|
|
|||
|
|
@ -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/fund/:id', require('./routes/xueqiu/fund'));
|
||||
|
||||
// Greasy Fork
|
||||
router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `https://xueqiu.com/S/F${ctx.params.id}`;
|
||||
|
||||
let fundName = await axios({
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
Referer: 'https://xueqiu.com/',
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(fundName.data);
|
||||
fundName = $('.stock-name').text();
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://fund.xueqiu.com/dj/open/fund/growth/${ctx.params.id}?day=7`,
|
||||
headers: {
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data.data.fund_nav_growth.pop();
|
||||
|
||||
let description = `${fundName} 最新净值 ${data.nav} <br> 今日`;
|
||||
|
||||
const value = parseFloat(data.value);
|
||||
|
||||
if (value > 0) {
|
||||
description += '涨幅';
|
||||
} else if (value < 0) {
|
||||
description += '跌幅';
|
||||
} else if (value === 0) {
|
||||
description += '无波动';
|
||||
}
|
||||
|
||||
description += ` ${data.value} ${data.percentage}%`;
|
||||
|
||||
ctx.state.data = {
|
||||
title: fundName,
|
||||
link: url,
|
||||
description: `${fundName} 净值更新`,
|
||||
item: [
|
||||
{
|
||||
title: `${fundName} ${data.date} 净值更新`,
|
||||
description,
|
||||
pubDate: new Date(data.date).toUTCString(),
|
||||
link: url,
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue