From 41fc70c1f0c989fd0e3319df13830e2f88feb3c1 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 3 Aug 2022 20:52:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8D=8E=E5=B0=94?= =?UTF-8?q?=E8=A1=97=E6=97=A5=E6=8A=A5=E6=9C=80=E7=83=AD=E6=96=87=E7=AB=A0?= =?UTF-8?q?=20(#10362)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 华尔街日报最热文章 * docs: fix typo * update lib/v2/wallstreetcn/maintainer.js --- docs/traditional-media.md | 28 ++++++++++++++-- lib/v2/wallstreetcn/hot.js | 56 +++++++++++++++++++++++++++++++ lib/v2/wallstreetcn/live.js | 27 +++++---------- lib/v2/wallstreetcn/maintainer.js | 3 +- lib/v2/wallstreetcn/news.js | 31 ++++++++++++----- lib/v2/wallstreetcn/radar.js | 6 ++++ lib/v2/wallstreetcn/router.js | 1 + 7 files changed, 122 insertions(+), 30 deletions(-) create mode 100644 lib/v2/wallstreetcn/hot.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 8b89581e7..1b6e63b54 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1100,9 +1100,29 @@ Type 栏目: ## 华尔街见闻 -### 华尔街见闻 +### 资讯 - + + +| id | 分类 | +| ------------ | -- | +| global | 最新 | +| shares | 股市 | +| bonds | 债市 | +| commodities | 商品 | +| forex | 外汇 | +| enterprise | 公司 | +| asset-manage | 资管 | +| tmt | 科技 | +| estate | 地产 | +| car | 汽车 | +| medicine | 医药 | + + + +### 最新 + + ### 实时快讯 @@ -1114,6 +1134,10 @@ Type 栏目: +### 最热文章 + + + ## 华尔街日报 The Wall Street Journal (WSJ) ### 新闻 diff --git a/lib/v2/wallstreetcn/hot.js b/lib/v2/wallstreetcn/hot.js new file mode 100644 index 000000000..20c8f06c9 --- /dev/null +++ b/lib/v2/wallstreetcn/hot.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const period = ctx.params.period ?? 'day'; + + const rootUrl = 'https://wallstreetcn.com'; + const apiRootUrl = 'https://api-one-wscn.awtmt.com'; + const apiUrl = `${apiRootUrl}/apiv1/content/articles/hot?period=all`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items = response.data.data[`${period}_items`].map((item) => ({ + guid: item.id, + link: item.uri, + pubDate: parseDate(item.display_time * 1000), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/apiv1/content/articles/${item.guid}?extract=0`, + }); + + const data = detailResponse.data.data; + + item.title = data.title || data.content_text; + item.author = data.source_name ?? data.author.display_name; + item.description = data.content + (data.content_more ?? ''); + item.category = data.asset_tags?.map((t) => t.name) ?? []; + + if (data.audio_uri) { + item.enclosure_type = 'audio/mpeg'; + item.enclosure_url = data.audio_uri; + item.itunes_item_image = data.image?.uri ?? ''; + item.itunes_duration = data.audio_info?.duration ?? ''; + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: '华尔街见闻 - 最热文章', + link: rootUrl, + item: items, + itunes_author: '华尔街见闻', + image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg', + }; +}; diff --git a/lib/v2/wallstreetcn/live.js b/lib/v2/wallstreetcn/live.js index 903077f0f..7e584ddd1 100644 --- a/lib/v2/wallstreetcn/live.js +++ b/lib/v2/wallstreetcn/live.js @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const rootUrl = 'https://wallstreetcn.com'; const apiRootUrl = 'https://api-one.wallstcn.com'; const currentUrl = `${rootUrl}/live/${category}`; - const apiUrl = `${apiRootUrl}/apiv1/content/lives?channel=${category}-channel&limit=${ctx.query.limit ?? 50}`; + const apiUrl = `${apiRootUrl}/apiv1/content/lives?channel=${category}-channel&limit=${ctx.query.limit ?? 100}`; const response = await got({ method: 'get', @@ -27,25 +27,16 @@ module.exports = async (ctx) => { const items = response.data.data.items .filter((item) => item.score >= score) - .map((item) => { - let author; - try { - author = item.author.display_name; - } catch (e) { - author = ''; - } - - return { - link: item.uri, - title: item.title || item.content_text, - description: item.content, - pubDate: parseDate(item.display_time * 1000), - author, - }; - }); + .map((item) => ({ + link: item.uri, + title: item.title || item.content_text, + description: item.content + (item.content_more ?? ''), + pubDate: parseDate(item.display_time * 1000), + author: item.author?.display_name ?? '', + })); ctx.state.data = { - title: `${titles[category]} - 实时快讯 - 华尔街见闻`, + title: `华尔街见闻 - 实时快讯 - ${titles[category]}`, link: currentUrl, item: items, }; diff --git a/lib/v2/wallstreetcn/maintainer.js b/lib/v2/wallstreetcn/maintainer.js index 9c3b0b14b..e78d32415 100644 --- a/lib/v2/wallstreetcn/maintainer.js +++ b/lib/v2/wallstreetcn/maintainer.js @@ -1,5 +1,6 @@ module.exports = { - '/live/:category?': ['nczitzk'], + '/hot/:period?': ['nczitzk'], + '/live/:category?/:score?': ['nczitzk'], '/news/:category?': ['nczitzk'], '/:category?': ['nczitzk'], }; diff --git a/lib/v2/wallstreetcn/news.js b/lib/v2/wallstreetcn/news.js index 9d9990239..90ca8248e 100644 --- a/lib/v2/wallstreetcn/news.js +++ b/lib/v2/wallstreetcn/news.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const titles = { @@ -21,8 +20,8 @@ module.exports = async (ctx) => { const rootUrl = 'https://wallstreetcn.com'; const apiRootUrl = 'https://api-one.wallstcn.com'; - const currentUrl = `${rootUrl}/live/${category}`; - const apiUrl = `${apiRootUrl}/apiv1/content/information-flow?channel=${category}-channel&accept=article&limit=25`; + const currentUrl = `${rootUrl}/news/${category}`; + const apiUrl = `${apiRootUrl}/apiv1/content/information-flow?channel=${category}-channel&accept=article&limit=${ctx.query.limit ?? 25}`; const response = await got({ method: 'get', @@ -30,9 +29,9 @@ module.exports = async (ctx) => { }); let items = response.data.data.items.map((item) => ({ + type: item.resource_type, + guid: item.resource.id, link: item.resource.uri, - title: item.resource?.title, - author: item.resource.author?.display_name, pubDate: parseDate(item.resource.display_time * 1000), })); @@ -41,12 +40,24 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const detailResponse = await got({ method: 'get', - url: item.link, + url: `${apiRootUrl}/apiv1/content/${item.type === 'live' ? `lives/${item.guid}` : `articles/${item.guid}?extract=0`}`, }); - const content = cheerio.load(detailResponse.data); + const data = detailResponse.data.data; - item.description = content('.rich-text, .live-detail-html').html(); + item.title = data.title || data.content_text; + item.author = data.source_name ?? data.author.display_name; + item.description = data.content + (data.content_more ?? ''); + item.category = data.asset_tags?.map((t) => t.name) ?? []; + + if (data.audio_uri) { + item.enclosure_type = 'audio/mpeg'; + item.enclosure_url = data.audio_uri; + item.itunes_item_image = data.image?.uri ?? ''; + item.itunes_duration = data.audio_info?.duration ?? ''; + } + + delete item.type; return item; }) @@ -54,8 +65,10 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: `${titles[category]} - 资讯 - 华尔街见闻`, + title: `华尔街见闻 - 资讯 - ${titles[category]}`, link: currentUrl, item: items, + itunes_author: '华尔街见闻', + image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg', }; }; diff --git a/lib/v2/wallstreetcn/radar.js b/lib/v2/wallstreetcn/radar.js index 2c2b4d1dd..f0f46dcf1 100644 --- a/lib/v2/wallstreetcn/radar.js +++ b/lib/v2/wallstreetcn/radar.js @@ -14,6 +14,12 @@ module.exports = { source: ['/live/:category', '/'], target: '/wallstreetcn/live/:category?', }, + { + title: '最热文章', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-er-jie-jian-wen-zui-re-wen-zhang', + source: ['/'], + target: '/wallstreetcn/hot/:period?', + }, ], }, }; diff --git a/lib/v2/wallstreetcn/router.js b/lib/v2/wallstreetcn/router.js index 6c24c3b9b..e352fd5e9 100644 --- a/lib/v2/wallstreetcn/router.js +++ b/lib/v2/wallstreetcn/router.js @@ -1,4 +1,5 @@ module.exports = function (router) { + router.get('/hot/:period?', require('./hot')); router.get('/live/:category?/:score?', require('./live')); router.get('/news/:category?', require('./news')); router.get('/:category?', require('./news'));