From 7b6ced8ab4581ba80733379be7f2aa60b078b335 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 9 Apr 2026 09:29:09 +0800 Subject: [PATCH] feat(route): add wkjyqh (#21666) * feat(route): add wkjyqh * fix: more accurate pubDate --- lib/routes/wkjyqh/namespace.ts | 8 ++++ lib/routes/wkjyqh/research.ts | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 lib/routes/wkjyqh/namespace.ts create mode 100644 lib/routes/wkjyqh/research.ts diff --git a/lib/routes/wkjyqh/namespace.ts b/lib/routes/wkjyqh/namespace.ts new file mode 100644 index 000000000..9f25ff9f1 --- /dev/null +++ b/lib/routes/wkjyqh/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '五矿期货', + url: 'www.wkjyqh.com', + categories: ['finance'], + lang: 'zh-CN', +}; diff --git a/lib/routes/wkjyqh/research.ts b/lib/routes/wkjyqh/research.ts new file mode 100644 index 000000000..31b6111a1 --- /dev/null +++ b/lib/routes/wkjyqh/research.ts @@ -0,0 +1,76 @@ +import { load } from 'cheerio'; + +import type { DataItem, Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/research', + categories: ['finance'], + example: '/wkjyqh/research', + radar: [ + { + source: ['www.wkjyqh.com/main/research_center/yjbg/index.shtml', 'www.wkjyqh.com/main/research_center/'], + }, + ], + name: '研究报告', + maintainers: ['TonyRL'], + handler, + url: 'www.wkjyqh.com/main/research_center/yjbg/index.shtml', +}; + +async function handler() { + const baseUrl = 'https://www.wkjyqh.com'; + const link = `${baseUrl}/main/research_center/yjbg/index.shtml`; + + const apiResponse = await ofetch(`${baseUrl}/servlet/json`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + funcNo: '2000153', + catalogId: '232', + pageNow: '1', + pageSize: '15', + isFilter: '1', + titleLength: '35', + briefLength: '70', + _catalogId: '', + rightId: '', + }), + responseType: 'json', + }); + + const list: DataItem[] = apiResponse.results[0].data.map((item) => ({ + title: item.title, + link: new URL(item.url, baseUrl).href, + pubDate: timezone(parseDate(item.publish_date), +8), + })); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link!, async () => { + const response = await ofetch(item.link!); + const $ = load(response); + + const content = $('.article_detail'); + item.pubDate = timezone(parseDate(content.find('b#time').text()), +8); + content.find('h2, .tips').remove(); + item.description = content.html()?.trim(); + + return item; + }) + ) + ); + + return { + title: '五矿期货 - 研究报告', + link, + language: 'zh-CN' as const, + image: `${baseUrl}/favicon.ico`, + item: items, + }; +}