feat: add 华尔街见闻实时快讯 (#5720)

This commit is contained in:
Ethan Shen
2020-09-25 11:46:27 +01:00
committed by GitHub
parent 10b975d73d
commit 3f5fc5d7fa
3 changed files with 55 additions and 0 deletions
+10
View File
@@ -283,6 +283,16 @@ Type 栏目:
<Route author="conanjunn" example="/wallstreetcn/news/global" path="/wallstreetcn/news/global" />
### 实时快讯
<Route author="nczitzk" example="/wallstreetcn/live" path="/wallstreetcn/live/:channel?" :paramsDesc="['快讯分类,默认`global`,见下表']">
| 要闻 | A 股 | 美股 | 港股 | 外汇 | 商品 | 理财 |
| ------ | ------- | -------- | -------- | ----- | --------- | --------- |
| global | a-stock | us-stock | hk-stock | forex | commodity | financing |
</Route>
## 极客公园
### 全球快讯
+1
View File
@@ -1209,6 +1209,7 @@ router.get('/allpoetry/:order?', require('./routes/allpoetry/order'));
// 华尔街见闻
router.get('/wallstreetcn/news/global', require('./routes/wallstreetcn/news'));
router.get('/wallstreetcn/live/:channel?', require('./routes/wallstreetcn/live'));
// 多抓鱼搜索
router.get('/duozhuayu/search/:wd', require('./routes/duozhuayu/search'));
+44
View File
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const config = {
global: '要闻',
'a-stock': 'A股',
'us-stock': '美股',
'hk-stock': '港股',
forex: '外汇',
commodity: '商品',
financing: '理财',
};
module.exports = async (ctx) => {
ctx.params.channel = ctx.params.channel || 'global';
const currentUrl = `https://wallstreetcn.com/live/${ctx.params.channel}`;
const rootUrl = `https://api.wallstcn.com/apiv1/content/lives?channel=${ctx.params.channel}-channel`;
const response = await got({
method: 'get',
url: rootUrl,
});
const items = response.data.data.items.map((item) => {
let title;
const match = item.content_text.match(/【(.*)】/);
if (match !== null) {
title = match[1];
} else {
title = item.content_text;
}
return {
title,
link: `https://wallstreetcn.com/livenews/${item.id}`,
pubDate: new Date(item.display_time * 1000).toUTCString(),
description: item.content,
};
});
ctx.state.data = {
title: `${config[ctx.params.channel]} - 实时快讯 - 华尔街见闻`,
link: currentUrl,
item: items,
};
};