Skip to content

Commit

Permalink
feat(route): 增加 金融界
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo committed Dec 20, 2024
1 parent 4bec9ed commit b1415b0
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
127 changes: 127 additions & 0 deletions lib/routes/jrj/index.ts
Original file line number Diff line number Diff line change
@@ -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: '/finance',
parameters: {
column: {
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: url,
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/jrj/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '金融界',
url: 'www.jrj.com.cn',
description: '金融界是国内领先的金融信息服务平台,日均触达千万用户,年度访问量超过3亿,受众覆盖中国主流金融机构、上市公司和活跃投资理财群体',
lang: 'zh-CN',
};

0 comments on commit b1415b0

Please sign in to comment.