From 32358de408aa83e1cdf65d72da4881d668770eed Mon Sep 17 00:00:00 2001 From: Cedar Date: Tue, 17 Dec 2024 20:57:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=A2=9E=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E6=99=AE=E5=85=A8=E7=90=83=E8=AF=84=E7=BA=A7=20(#17913)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 增加标普全球评级 增加标普全球评级多语言发布稿件的获取,https://www.spglobal.com/ratings/zh、https://www.spglo bal.com/ratings/en等 * chore: provide an absolute URL. * chore: fix incorrect URL --------- Co-authored-by: Cedar --- lib/routes/spglobal/namespace.ts | 7 ++++ lib/routes/spglobal/ratings.ts | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 lib/routes/spglobal/namespace.ts create mode 100644 lib/routes/spglobal/ratings.ts diff --git a/lib/routes/spglobal/namespace.ts b/lib/routes/spglobal/namespace.ts new file mode 100644 index 00000000000000..cbdfcf54bf062b --- /dev/null +++ b/lib/routes/spglobal/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'S&P Global', + url: 'www.spglobal.com', + lang: 'en', +}; diff --git a/lib/routes/spglobal/ratings.ts b/lib/routes/spglobal/ratings.ts new file mode 100644 index 00000000000000..b6ba748231a850 --- /dev/null +++ b/lib/routes/spglobal/ratings.ts @@ -0,0 +1,64 @@ +import { Route, ViewType } from '@/types'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; + +export const route: Route = { + path: '/ratings/:language?', + categories: ['finance'], + view: ViewType.Notifications, + example: '/spglobal/ratings/en', + parameters: { + language: { + description: '语言', + options: [ + { value: 'zh', label: '中文' }, + { value: 'en', label: 'English' }, + { value: 'es', label: 'Español' }, + { value: 'pt', label: 'Português' }, + { value: 'jp', label: '日本語' }, + { value: 'ru', label: 'Русский' }, + { value: 'ar', label: 'العربية' }, + ], + }, + }, + radar: [ + { + source: ['www.spglobal.com/ratings/:language'], + }, + ], + name: 'Ratings', + description: ` +| language | Description | +| --- | --- | +| zh | 中文 | +| en | English | +| es | Español | +| pt | Português | +| jp | 日本語 | +| ru | Русский | +| ar | العربية | + `, + maintainers: ['FYLSen'], + handler, +}; + +async function handler(ctx) { + const language = ctx.req.param('language'); + + const responseData = await got( + `https://www.spglobal.com/crownpeaksearchproxy.aspx?q=https%3A%2F%2Fsearchg2-restricted.crownpeak.net%2Fsandpglobal-spglobal-live%2Fselect%3Fq%3D*%253A*%26echoParams%3Dexplicit%26fl%3Dtitle%2Ccustom_i_article_id%2Ccustom_ss_theme%2Ccustom_ss_theme_full%2Ccustom_dt_meta_publish_date%2Ccustom_s_meta_location%20%2Ccustom_s_local_url%2Ccustom_s_tile_image%2Ccustom_s_cshtml_path%2Ccustom_s_sub_type%2Ccustom_s_meta_type%2Cscore%2Ccustom_s_division%2Ccustom_ss_contenttype%2Ccustom_ss_location%2Ccustom_ss_region%2Ccustom_ss_theme%2Ccustom_ss_author_thumbnails%2Ccustom_ss_authors%2Ccustom_ss_author_titles%2Ccustom_s_meta_videoid%2Ctaxonomy_tag_freeform%2Ccustom_ss_tags%2Ccustom_ss_freeform%26defType%3Dedismax%26wt%3Djson%26start%3D0%26rows%3D10%26fq%3Dcustom_s_type%3Aarticle%26fq%3Dcustom_s_sub_type%3A(%22blog%22%2C%20%22news%22%2C%20%22research%22%2C%20%22podcast%22%2C%20%22video%22%2C%20%22article%22%2C%20%22pdf%20details%22)%26fq%3Dcustom_s_division%3A%22Ratings%22%26fq%3Dcustom_s_region%3A%22${language}%22%26facet%3Dtrue%26facet.mincount%3D1%26facet.field%3Dcustom_ss_theme_full%26facet.limit%3D15%26sort%3Dcustom_dt_meta_publish_date%20desc%26f.custom_ss_theme_full.facet.sort%3Dindex` + ); + + const items = responseData?.data?.response?.docs || []; + + return { + title: `S&P Global Ratings(${language})`, + link: `https://www.spglobal.com/ratings/${language}/`, + allowEmpty: true, + item: items.map((x) => ({ + title: x.title, + pubDate: parseDate(x.custom_dt_meta_publish_date), + link: `https://www.spglobal.com${x.custom_s_local_url}`, + })), + }; +}