Skip to content

Commit

Permalink
style(route/cffex): modify code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenXiangcheng1 committed Jul 26, 2024
1 parent 0aa9369 commit 20c7a78
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions lib/routes/cffex/announcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import cache from '@/utils/cache';

export const route: Route = {
path: '/announcement',
name: '中国金融期货交易所 - 交易所公告',
name: '交易所公告',
url: 'www.cffex.com.cn',
maintainers: ['ChenXiangcheng1'],
example: '/cffex/announcement',
parameters: {},
description: `欢迎订阅!!! 我维护的 cffex 交易所公告!!! `,
description: '',
categories: ['government'],
features: {
requireConfig: false,
Expand All @@ -25,7 +25,7 @@ export const route: Route = {
radar: [
{
source: ['cffex.com.cn'],
target: '/cffex/announcement',
target: '/announcement',
},
],
handler,
Expand All @@ -34,46 +34,39 @@ export const route: Route = {
async function handler(): Promise<{ title: string; link: string; item: DataItem[] }> {
const baseUrl = 'http://www.cffex.com.cn';
const homeUrl = `${baseUrl}/jystz`;
const response = await ofetch(homeUrl, {
headers: {},
});
const response = await ofetch(homeUrl);

// 使用 Cheerio 选择器解析 HTML
const $ = load(response);
const list = $('div.notice_list li')
.toArray()
.map((item) => {
item = $(item); // (Element) -> LoadedCheerio
const a1 = $(item).find('a').first();
const a2 = $(item).find('a').eq(1);
const titleEle = $(item).find('a').first();
const dateEle = $(item).find('a').eq(1);

return {
title: a1.text().trim(),
link: `${baseUrl}${a1.attr('href')}`,
pubDate: timezone(parseDate(a2.text(), 'YYYY-MM-DD'), +8),
title: titleEle.text().trim(),
link: `${baseUrl}${titleEle.attr('href')}`,
pubDate: timezone(parseDate(dateEle.text(), 'YYYY-MM-DD'), +8),
};
});

// (Promise) -> Promise
const items = await Promise.all(
// (Promise|null) -> Promise|null
list.map((item) =>
cache.tryGet(
item.link,
async () => {
const response = await ofetch(item.link);
const $ = load(response);
item.description = $('div.jysggnr div.nan p').eq(1)?.html();
return item;
},
3600,
true
)
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
item.description = $('div.jysggnr div.nan p').eq(1)?.html();
return item;
})
)
);

return {
title: `中国金融期货交易所 - 交易所公告`,
title: '中国金融期货交易所 - 交易所公告',
link: homeUrl,
item: items,
};
Expand Down

0 comments on commit 20c7a78

Please sign in to comment.