From 6cd621d1045aa6b75979f946ad020fe8d0b47caf Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Thu, 26 Dec 2024 00:09:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=A2=9E=E5=8A=A0=20=E9=87=91?= =?UTF-8?q?=E8=9E=8D=E7=95=8C=20(#17943)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/jrj/index.ts | 127 ++++++++++++++++++++++++++++++++++++ lib/routes/jrj/namespace.ts | 8 +++ 2 files changed, 135 insertions(+) create mode 100644 lib/routes/jrj/index.ts create mode 100644 lib/routes/jrj/namespace.ts diff --git a/lib/routes/jrj/index.ts b/lib/routes/jrj/index.ts new file mode 100644 index 00000000000000..70d71c1abe55ea --- /dev/null +++ b/lib/routes/jrj/index.ts @@ -0,0 +1,127 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { ofetch } from 'ofetch'; + +const options = { + '103': '财经资讯', + '508': '科技资讯', + '106': '商业资讯', + '632': '消费资讯', + '630': '医疗资讯', + '119': '康养资讯', + '004': '汽车资讯', + '009': '房产资讯', + '629': 'ESG 资讯', + '010': 'A股资讯', + '001': '港股资讯', + '102': '美股资讯', + '113': '银行资讯', + '115': '保险资讯', + '104': '基金资讯', + '503': '私募资讯', + '112': '信托资讯', + '007': '外汇资讯', + '107': '期货资讯', + '118': '债券资讯', + '603': '券商资讯', + '105': '观点', +}; + +export const route: Route = { + path: '/:channelNum', + categories: ['finance'], + example: '/jrj/103', + parameters: { + channelNum: { + description: '栏目编号', + options: Object.entries(options).map(([value, label]) => ({ value, label })), + }, + }, + url: 'www.jrj.com.cn', + name: '资讯', + description: ` +| column | Description | +| --- | --- | +| 103 | 财经资讯 | +| 508 | 科技资讯 | +| 106 | 商业资讯 | +| 632 | 消费资讯 | +| 630 | 医疗资讯 | +| 119 | 康养资讯 | +| 004 | 汽车资讯 | +| 009 | 房产资讯 | +| 629 | ESG 资讯 | +| 001 | 港股资讯 | +| 102 | 美股资讯 | +| 113 | 银行资讯 | +| 115 | 保险资讯 | +| 104 | 基金资讯 | +| 503 | 私募资讯 | +| 112 | 信托资讯 | +| 007 | 外汇资讯 | +| 107 | 期货资讯 | +| 118 | 债券资讯 | +| 603 | 券商资讯 | +| 105 | 观点 | + `, + maintainers: ['p3psi-boo'], + handler, +}; + +async function handler(ctx) { + const channelNum = ctx.req.param('channelNum'); + + const url = 'https://gateway.jrj.com/jrj-news/news/queryNewsList'; + + const response = await ofetch(url, { + method: 'post', + body: { + sortBy: 1, + pageSize: 20, + makeDate: '', + channelNum, + infoCls: '', + }, + }); + + const alist = response.data.data; + + const list = alist.map((item) => { + const link = item.pcInfoUrl; + const title = item.title; + const author = item.paperMediaSource; + const pubDate = parseDate(item.makeDate); + + return { + title, + link, + author, + pubDate, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const articleUrl = item.link; + const response = await ofetch(articleUrl); + + const $ = load(response); + + const content = $('.article_content').html(); + + item.description = content; + return item; + }) + ) + ); + + return { + title: `${options[channelNum]} - 金融界`, + link: 'https://jrj.com', + item: items, + }; +} diff --git a/lib/routes/jrj/namespace.ts b/lib/routes/jrj/namespace.ts new file mode 100644 index 00000000000000..3961cae5b5fcaa --- /dev/null +++ b/lib/routes/jrj/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '金融界', + url: 'www.jrj.com.cn', + description: '金融界是国内领先的金融信息服务平台,日均触达千万用户,年度访问量超过3亿,受众覆盖中国主流金融机构、上市公司和活跃投资理财群体', + lang: 'zh-CN', +};