From 3f5fc5d7fab83414d4b67d0a0daa8359c267d4a4 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 25 Sep 2020 18:46:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=8D=8E=E5=B0=94=E8=A1=97?= =?UTF-8?q?=E8=A7=81=E9=97=BB=E5=AE=9E=E6=97=B6=E5=BF=AB=E8=AE=AF=20(#5720?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/traditional-media.md | 10 ++++++++ lib/router.js | 1 + lib/routes/wallstreetcn/live.js | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/wallstreetcn/live.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index fc91b291fd..528d04f1b2 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -283,6 +283,16 @@ Type 栏目: +### 实时快讯 + + + +| 要闻 | A 股 | 美股 | 港股 | 外汇 | 商品 | 理财 | +| ------ | ------- | -------- | -------- | ----- | --------- | --------- | +| global | a-stock | us-stock | hk-stock | forex | commodity | financing | + + + ## 极客公园 ### 全球快讯 diff --git a/lib/router.js b/lib/router.js index 5a85fd5881..3a5250e9fc 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/wallstreetcn/live.js b/lib/routes/wallstreetcn/live.js new file mode 100644 index 0000000000..6455fea5d8 --- /dev/null +++ b/lib/routes/wallstreetcn/live.js @@ -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, + }; +};