feat: 又双叒叕更改股票路由 (#4093)

This commit is contained in:
Henry Wang 2020-02-27 04:36:24 +00:00 committed by GitHub
parent af48722ba9
commit 4bcaefa093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -42,7 +42,7 @@ module.exports = async (ctx) => {
const name = $('.fullview-title b').text();
ctx.state.data = {
title: `${name} News by Finviz`,
title: `${ctx.params.ticker} ${name} News by Finviz`,
link,
description: `A collection of ${name} news aggregated by Finviz.`,
item,

View File

@ -22,7 +22,9 @@ module.exports = async (ctx) => {
const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0];
const $ = cheerio.load(res1.data); // 使用 cheerio 加载返回的 HTML
const stock_name = $('.stock-name').text();
const stock_name = $('.stock-name')
.text()
.split('(')[0];
let query_url = 'https://xueqiu.com/statuses';
if (source === 'all') {
@ -52,14 +54,20 @@ module.exports = async (ctx) => {
const data = res2.data.list;
ctx.state.data = {
title: `${stock_name} - ${source}`,
title: `${id} ${stock_name} - ${source}`,
link: `https://xueqiu.com/S/${id}`,
description: `${stock_name} - ${source}`,
item: data.map((item) => ({
title: item.title !== '' ? item.title : item.description.replace(/<[^>]+>/g, ''),
description: item.description,
pubDate: new Date(item.created_at).toUTCString(),
link: `https://xueqiu.com${item.target}`,
})),
item: data.map((item) => {
let link = `https://xueqiu.com${item.target}`;
if (item.quote_cards) {
link = item.quote_cards[0].target_url;
}
return {
title: item.title !== '' ? item.title : item.description.replace(/<[^>]+>/g, ''),
description: item.description,
pubDate: new Date(item.created_at).toUTCString(),
link,
};
}),
};
};