Skip to content

Commit

Permalink
feat(route): Add 上海业余无线电协会 (#15290)
Browse files Browse the repository at this point in the history
* feat(route): Add 上海业余无线电协会

* fix(route): fix type error
  • Loading branch information
HChenZi authored Apr 19, 2024
1 parent 6a80296 commit 1a3720a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions lib/routes/sara/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Route, DataItem } from '@/types';
import cache from '@/utils/cache';
import { load } from 'cheerio';
import { ofetch } from 'ofetch';

const typeMap = {
dynamic: '协会动态',
announcement: '通知公告',
industry: '行业动态',
};

export const route: Route = {
path: '/:type',
categories: ['government'],
example: '/sara/announcement',
parameters: { type: 'dynamic | announcement | industry' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
description: `| 协会动态 | 通知公告 |行业动态 |
| -------- | ------------ | -------- |
| dynamic | announcement | industry |`,

name: '新闻资讯',
maintainers: ['HChenZi'],
handler: async (ctx) => {
const baseUrl = 'http://www.sara.org.cn';
const type = ctx.req.param('type');

const url = `${baseUrl}/news/${type}.htm`;
const response = await ofetch(url);
const $ = load(response);
const list = $('.newsItem_total > dd')
.toArray()
.map((item) => {
const a = $(item).find('a').first();
return {
link: `${baseUrl}${a.attr('href')}`,
title: a.attr('title'),
};
});
const items = (await Promise.all(list.map(getFeedItem))) as DataItem[];
return {
title: typeMap[type],
link: url,
item: items,
};
},
};

async function getFeedItem(item) {
return await cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
return {
description: $('.text').html(),
language: 'zh-cn',
...item,
};
});
}
6 changes: 6 additions & 0 deletions lib/routes/sara/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '上海业余无线电协会',
url: 'www.sara.org.cn',
};

0 comments on commit 1a3720a

Please sign in to comment.