feat(route): wallstreetcn (#17597)
* feat(route): wallstreetcn * fix(route): correct country_id reference in link generation
This commit is contained in:
parent
4b6658605a
commit
adbe01dad7
|
|
@ -0,0 +1,90 @@
|
|||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/calendar/:section?',
|
||||
categories: ['finance'],
|
||||
example: '/wallstreetcn/calendar',
|
||||
parameters: { section: '`macrodatas` 或 `report`,默认为 `macrodatas`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['wallstreetcn.com/calendar'],
|
||||
},
|
||||
],
|
||||
name: '财经日历',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
url: 'wallstreetcn.com/calendar',
|
||||
};
|
||||
|
||||
const rootUrl = 'https://wallstreetcn.com';
|
||||
|
||||
const MacrodataSuffix = {
|
||||
CA: 'CA10YR.OTC',
|
||||
CN: 'USDCNH.OTC',
|
||||
DE: 'DE30.OTC',
|
||||
FR: 'FR40.OTC',
|
||||
// HK: '',
|
||||
IT: 'EURUSD.OTC',
|
||||
JP: 'USDJPY.OTC',
|
||||
UK: 'UK100.OTC',
|
||||
US: 'DXY.OTC',
|
||||
};
|
||||
|
||||
const getMacrodataUrl = (countryId, wscnTicker) => `${rootUrl}/data-analyse/${wscnTicker}/${MacrodataSuffix[countryId]}`;
|
||||
|
||||
async function handler(ctx) {
|
||||
const { section = 'macrodatas' } = ctx.req.param();
|
||||
|
||||
const link = `${rootUrl}/calendar`;
|
||||
const apiRootUrl = section === 'macrodatas' ? 'https://api-one-wscn.awtmt.com' : 'https://api-ddc-wscn.awtmt.com';
|
||||
const apiUrl = section === 'macrodatas' ? `${apiRootUrl}/apiv1/finance/macrodatas` : `${apiRootUrl}/finance/report/list`;
|
||||
|
||||
const response = await ofetch(apiUrl, {
|
||||
query:
|
||||
section === 'macrodatas'
|
||||
? {
|
||||
start: new Date().setHours(0, 0, 0, 0) / 1000,
|
||||
end: Math.trunc(new Date().setHours(23, 59, 59, 999) / 1000),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
const items =
|
||||
section === 'macrodatas'
|
||||
? response.data.items.map((item) => ({
|
||||
title: `${item.country}${item.title}`,
|
||||
description: `${item.country}${item.title} 重要性: ${'★'.repeat(item.importance)} 今值: ${item.actual || '-'}${item.actual && item.unit} 预期: ${item.forecast || '-'}${item.forecast && item.unit} 前值: ${item.revised || item.previous || '-'}${(item.revised || item.previous) && item.unit}`,
|
||||
link: item.uri && MacrodataSuffix[item.country_id] && getMacrodataUrl(item.country_id, item.wscn_ticker),
|
||||
guid: item.id,
|
||||
pubDate: parseDate(item.public_date, 'X'),
|
||||
category: item.country,
|
||||
}))
|
||||
: // report
|
||||
response.data.items
|
||||
.map((item) => Object.fromEntries(response.data.fields.map((field, index) => [field, item[index]])))
|
||||
.map((item) => ({
|
||||
title: `${item.company_name} ${item.observation_date}`,
|
||||
description: `${item.code} ${item.company_name} ${item.observation_date} 预期EPS: ${item.eps_estimate === 0 ? '-' : item.eps_estimate} 实际EPS: ${item.reported_eps === 0 ? '-' : item.reported_eps} 差异度: ${item.surprise === 0 || item.surprise === -1 ? '-' : (item.surprise * 100).toFixed(2) + '%'}`,
|
||||
link,
|
||||
guid: item.id,
|
||||
pubDate: parseDate(item.public_date, 'X'),
|
||||
}));
|
||||
|
||||
return {
|
||||
title: '财经日历 - 华尔街见闻',
|
||||
link,
|
||||
item: items,
|
||||
itunes_author: '华尔街见闻',
|
||||
image: 'https://static.wscn.net/wscn/_static/favicon.png',
|
||||
};
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import { parseDate } from '@/utils/parse-date';
|
|||
|
||||
export const route: Route = {
|
||||
path: '/hot/:period?',
|
||||
categories: ['traditional-media'],
|
||||
categories: ['finance'],
|
||||
example: '/wallstreetcn/hot',
|
||||
parameters: { period: '时期,可选 `day` 即 当日 或 `week` 即 当周,默认为当日' },
|
||||
features: {
|
||||
|
|
@ -77,6 +77,6 @@ async function handler(ctx) {
|
|||
link: rootUrl,
|
||||
item: items,
|
||||
itunes_author: '华尔街见闻',
|
||||
image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg',
|
||||
image: 'https://static.wscn.net/wscn/_static/favicon.png',
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const titles = {
|
|||
|
||||
export const route: Route = {
|
||||
path: '/live/:category?/:score?',
|
||||
categories: ['traditional-media'],
|
||||
categories: ['finance'],
|
||||
example: '/wallstreetcn/live',
|
||||
parameters: { category: '快讯分类,默认`global`,见下表', score: '快讯重要度,默认`1`全部快讯,可设置为`2`只看重要的' },
|
||||
features: {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,15 @@ const titles = {
|
|||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: ['/news/:category?', '/:category?'],
|
||||
path: '/news/:category?',
|
||||
categories: ['finance'],
|
||||
example: '/wallstreetcn/news',
|
||||
radar: [
|
||||
{
|
||||
source: ['wallstreetcn.com/news/:category', 'wallstreetcn.com/'],
|
||||
},
|
||||
],
|
||||
name: 'Unknown',
|
||||
name: '资讯',
|
||||
maintainers: ['nczitzk'],
|
||||
handler,
|
||||
description: `| id | 分类 |
|
||||
|
|
@ -98,6 +100,6 @@ async function handler(ctx) {
|
|||
link: currentUrl,
|
||||
item: items,
|
||||
itunes_author: '华尔街见闻',
|
||||
image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg',
|
||||
image: 'https://static.wscn.net/wscn/_static/favicon.png',
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue