添加雪球股票的公告,研报,新闻 (#1671)

This commit is contained in:
Yu Yang
2019-03-04 19:14:29 +08:00
committed by DIYgod
parent fc4c7725a1
commit f791d27d85
3 changed files with 60 additions and 0 deletions

View File

@@ -608,6 +608,12 @@ RSSHub 提供下列 API 接口:
<route name="基金净值更新" author="HenryQW" example="/xueqiu/fund/040008" path="/xueqiu/fund/:id" :paramsDesc="['基金代码, 可在基金主页 URL 中找到. 此路由的数据为场外基金 (`F`开头)']"/>
<route name="股票信息" author="YuYang" example="/xueqiu/stock_info/SZ000002" path="/xueqiu/stock_info/:id/:type?" :paramsDesc="['股票代码(需要带上交易所)', '动态的类型, 不填则为股票公告']">
| 公告 | 新闻 | 研报 |
| ------------ | ---- | -------- |
| announcement | news | research |
### 龙腾网
<route name="转译网贴" author="sgqy" example="/ltaaa" path="/ltaaa/:type?" :paramsDesc="['热门类型.']">

View File

@@ -463,6 +463,7 @@ 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'));
router.get('/xueqiu/stock_info/:id/:type?', require('./routes/xueqiu/stock_info'));
// Greasy Fork
router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts'));

View File

@@ -0,0 +1,53 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const type = ctx.params.type || 'announcement';
const count = 10;
const page = 1;
const typename = {
announcement: '公告',
news: '自选股新闻',
research: '研报',
};
const source = typename[type];
const res1 = await axios({
method: 'get',
url: `https://xueqiu.com/S/${id}`,
});
const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0];
const $ = cheerio.load(res1.data); // 使用 cheerio 加载返回的 HTML
const html_title = $('title').text();
const stock_name = html_title.split(' ')[0];
const res2 = await axios({
method: 'get',
url: 'https://xueqiu.com/statuses/stock_timeline.json',
params: {
symbol_id: id,
source: source,
count: count,
page: page,
},
headers: {
Cookie: token,
Referer: `https://xueqiu.com/u/${id}`,
},
});
const data = res2.data.list;
ctx.state.data = {
title: `${stock_name}${source}`,
link: `https://xueqiu.com/S/${id}`,
description: `${stock_name}${source}`,
item: data.map((item) => ({
title: item.title !== '' ? item.title : item.description.split('<a')[0],
description: item.description,
pubDate: new Date(item.created_at).toUTCString(),
link: `https://xueqiu.com${item.target}`,
})),
};
};