Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): wallstreetcn #17597

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions lib/routes/wallstreetcn/calendar.ts
Original file line number Diff line number Diff line change
@@ -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',
};
}
4 changes: 2 additions & 2 deletions lib/routes/wallstreetcn/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
};
}
2 changes: 1 addition & 1 deletion lib/routes/wallstreetcn/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions lib/routes/wallstreetcn/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 | 分类 |
Expand Down Expand Up @@ -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',
};
}