From 76b4feb92bc74dbd0bdb43d1f2ec77424efc771d Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Sun, 7 Oct 2018 09:02:02 +0100 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E9=9B=AA=E7=90=83?= =?UTF-8?q?=E5=9F=BA=E9=87=91=E5=87=80=E5=80=BC=E6=9B=B4=E6=96=B0=20(#828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 ++ router.js | 1 + routes/xueqiu/fund.js | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 routes/xueqiu/fund.js diff --git a/docs/README.md b/docs/README.md index 2428ed11a..16e7a0668 100644 --- a/docs/README.md +++ b/docs/README.md @@ -494,6 +494,8 @@ RSSHub 提供下列 API 接口: + + ## 编程 ### 掘金 diff --git a/router.js b/router.js index 12ea522c9..d8e1372ae 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/fund/:id', require('./routes/xueqiu/fund')); // Greasy Fork router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts')); diff --git a/routes/xueqiu/fund.js b/routes/xueqiu/fund.js new file mode 100644 index 000000000..19bc99b80 --- /dev/null +++ b/routes/xueqiu/fund.js @@ -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}
今日`; + + 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, + }, + ], + }; +};