feat(route): add 华尔街日报最热文章 (#10362)

* feat(route): add 华尔街日报最热文章

* docs: fix typo

* update lib/v2/wallstreetcn/maintainer.js
This commit is contained in:
Ethan Shen 2022-08-03 20:52:39 +08:00 committed by GitHub
parent b3be740e2f
commit 41fc70c1f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 30 deletions

View File

@ -1100,9 +1100,29 @@ Type 栏目:
## 华尔街见闻
### 华尔街见闻
### 资讯
<Route author="conanjunn" example="/wallstreetcn/news/global" path="/wallstreetcn/news/global" />
<Route author="nczitzk" example="/wallstreetcn/global" path="/wallstreetcn/:category?" :paramsDesc="['资讯分类,默认`global`,见下表']">
| id | 分类 |
| ------------ | -- |
| global | 最新 |
| shares | 股市 |
| bonds | 债市 |
| commodities | 商品 |
| forex | 外汇 |
| enterprise | 公司 |
| asset-manage | 资管 |
| tmt | 科技 |
| estate | 地产 |
| car | 汽车 |
| medicine | 医药 |
</Route>
### 最新
<Route author="conanjunn nczitzk" example="/wallstreetcn/news/global" path="/wallstreetcn/news/global" />
### 实时快讯
@ -1114,6 +1134,10 @@ Type 栏目:
</Route>
### 最热文章
<Route author="nczitzk" example="/wallstreetcn/hot" path="/wallstreetcn/hot/:period?" :paramsDesc="['时期,可选 `day` 即 当日 或 `week` 即 当周,默认为当日']"/>
## 华尔街日报 The Wall Street Journal (WSJ)
### 新闻

View File

@ -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',
};
};

View File

@ -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,
};

View File

@ -1,5 +1,6 @@
module.exports = {
'/live/:category?': ['nczitzk'],
'/hot/:period?': ['nczitzk'],
'/live/:category?/:score?': ['nczitzk'],
'/news/:category?': ['nczitzk'],
'/:category?': ['nczitzk'],
};

View File

@ -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',
};
};

View File

@ -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?',
},
],
},
};

View File

@ -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'));