Skip to content

Commit

Permalink
feat(routes): 新增深圳市医疗器械行业协会和中国食品土畜进出口商会 (DIYgod#15964)
Browse files Browse the repository at this point in the history
* feat(routes): 新增深圳市医疗器械行业协会和中国食品土畜进出口商会

* Update lib/routes/cccfna/index.ts

Co-authored-by: Tony <[email protected]>

* Update lib/routes/samd/news.ts

Co-authored-by: Tony <[email protected]>

* update

---------
  • Loading branch information
hualiong authored Jun 23, 2024
1 parent a1abbfc commit e455fe7
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
82 changes: 82 additions & 0 deletions lib/routes/cccfna/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Route, DataItem } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { load } from 'cheerio';
import { ofetch } from 'ofetch';

export const route: Route = {
path: '/:category/:type?',
categories: ['government'],
example: '/cccfna/meirigengxin',
parameters: {
category: '文章种类,即一级分类,详情见下表',
type: '文章类型,即二级分类,详情见下表',
},
radar: [
{
source: ['www.cccfna.org.cn/:category/:type?'],
},
],
description: `
:::tip
存在**二级分类**的**一级分类**不能单独当作参数,如:\`/cccfna/hangyezixun\`
:::
文章的目录分级如下:
- shanghuidongtai(商会通知)
- meirigengxin(每日更新)
- tongzhigonggao(通知公告)
- hangyezixun(行业资讯)
- zhengcedaohang(政策导航)
- yujinxinxi(预警信息)
- shichangdongtai(市场动态)
- gongxuxinxi(供需信息)
- maoyitongji(贸易统计)
- tongjikuaibao(统计快报)
- hangyetongji(行业统计)
- guobiemaoyi(国别贸易)
- maoyizhinan(贸易指南)
- nongchanpinbaogao(农产品报告)
- nongchanpinyuebao(农产品月报)
- zhongdianchanpinyuebao(重点产品月报)
- zhongdianchanpinzoushi(重点产品走势)`,
name: '资讯信息',
maintainers: ['hualiong'],
handler: async (ctx) => {
const { category, type } = ctx.req.param();
const baseURL = `https://www.cccfna.org.cn/${category}${type ? '/' + type : ''}`;

const response = await ofetch(baseURL);
const $ = load(response);

const list: DataItem[] = $('body > script')
.last()
.text()
.match(new RegExp(`https://www.cccfna.org.cn/${category}/.+?.html`, 'g'))!
.slice(0, 15)
.map((link) => ({ title: '', link }));

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link!, async () => {
const $ = load(await ofetch(item.link!));
const content = $('.list_cont');

item.title = content.find('.title').text();
item.pubDate = timezone(parseDate(content.find('.tip > .time').text(), '发布时间:YYYY-MM-DD'), +8);
item.description = content.find('#article-content').html()!;

return item;
})
)
);

return {
title: $('head > title').text(),
link: baseURL,
item: items as DataItem[],
};
},
};
6 changes: 6 additions & 0 deletions lib/routes/cccfna/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.cccfna.org.cn',
};
6 changes: 6 additions & 0 deletions lib/routes/samd/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.samd.org.cn',
};
74 changes: 74 additions & 0 deletions lib/routes/samd/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Route, DataItem } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { load } from 'cheerio';
import { ofetch } from 'ofetch';

const dict = { '434': '行业资讯', '436': '协会动态', '438': '重要通知', '440': '政策法规' };

export const route: Route = {
path: 'news/:typeId',
categories: ['government'],
example: '/samd/news/440',
parameters: { type: '文章类型ID,见下表' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
description: `| 行业资讯 | 协会动态 | 重要通知 | 政策法规 |
| --- | --- | --- | --- |
| 434 | 436 | 438 | 440 |`,
name: '资讯信息',
maintainers: ['hualiong'],
handler: async (ctx) => {
const baseURL = 'https://www.samd.org.cn/home';
const typeId = ctx.req.param('typeId');

const { rows } = await ofetch('/GetNewsByTagId', {
baseURL,
method: 'POST',
query: {
page: 1,
rows: 10,
typeId,
status: 1,
},
});

const list: DataItem[] = rows.map((row) => ({
title: row.title,
category: [row.tag_names],
link: `${baseURL}/newsDetail?id=${row.auto_id}&typeId=${typeId}`,
image: row.img_url ? baseURL + row.img_url : null,
}));

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link!, async () => {
const $ = load(await ofetch(item.link!));

const content = $('.content');
item.author = content.find('.author span').text();
item.pubDate = timezone(parseDate(content.find('.time').text(), '发布时间:YYYY-MM-DD HH:mm:ss'), +8);

content.children('.titles').remove();
content.children('.auxi').remove();
item.description = content.html()!;

return item;
})
)
);

return {
title: `${dict[typeId]} - 深圳市医疗器械行业协会`,
link: 'https://www.samd.org.cn/home/newsList',
item: items as DataItem[],
};
},
};

0 comments on commit e455fe7

Please sign in to comment.