From 0e1762f392057711304754cee611f57e3471b8ef Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:46:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=20=E5=92=8C?= =?UTF-8?q?=E8=AE=AF=E5=88=9B=E6=8A=95=20(#17842)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/hexun/index.ts | 74 +++++++++++++++++++++++++++++++++++ lib/routes/hexun/namespace.ts | 8 ++++ 2 files changed, 82 insertions(+) create mode 100644 lib/routes/hexun/index.ts create mode 100644 lib/routes/hexun/namespace.ts diff --git a/lib/routes/hexun/index.ts b/lib/routes/hexun/index.ts new file mode 100644 index 00000000000000..b4860c48073bbd --- /dev/null +++ b/lib/routes/hexun/index.ts @@ -0,0 +1,74 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +const decoder = new TextDecoder('gbk'); + +export const route: Route = { + path: '/pe/news', + categories: ['finance'], + example: '/hexun/pe/news', + url: 'pe.hexun.com/news/', + name: '创投行业新闻', + maintainers: ['p3psi-boo'], + handler, +}; + +async function handler() { + const baseUrl = 'https://pe.hexun.com/news/'; + + const response = await got({ + method: 'get', + url: baseUrl, + responseType: 'arrayBuffer', + }); + + const $ = load(decoder.decode(response.data)); + + const list = $('.listNews li') + .toArray() + .map((item) => { + const element = $(item); + const a = element.find('a'); + + const link = a.attr('href')?.replace('http://', 'https://') || ''; + const title = a.text() || ''; + + const timeSpan = element.find('span'); + const dateText = timeSpan.text().slice(1, timeSpan.text().length - 1); + const pubDate = parseDate(dateText, 'MM/DD HH:mm'); + + return { + title, + link, + pubDate, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + responseType: 'arrayBuffer', + }); + + const $ = load(decoder.decode(response.data)); + + item.description = $('.art_contextBox').html() || ''; + + return item; + }) + ) + ); + + return { + title: '和讯创投 - 创投行业新闻', + link: baseUrl, + item: items, + }; +} diff --git a/lib/routes/hexun/namespace.ts b/lib/routes/hexun/namespace.ts new file mode 100644 index 00000000000000..1870d0e18984a8 --- /dev/null +++ b/lib/routes/hexun/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '和讯网', + url: 'hexun.com', + description: '', + lang: 'zh-CN', +};