diff --git a/lib/routes/cccfna/index.ts b/lib/routes/cccfna/index.ts new file mode 100644 index 000000000..9034a8e5d --- /dev/null +++ b/lib/routes/cccfna/index.ts @@ -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[], + }; + }, +}; diff --git a/lib/routes/cccfna/namespace.ts b/lib/routes/cccfna/namespace.ts new file mode 100644 index 000000000..62dfb3f36 --- /dev/null +++ b/lib/routes/cccfna/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '中国食品土畜进出口商会', + url: 'www.cccfna.org.cn', +}; diff --git a/lib/routes/samd/namespace.ts b/lib/routes/samd/namespace.ts new file mode 100644 index 000000000..5c65df16a --- /dev/null +++ b/lib/routes/samd/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '深圳市医疗器械行业协会', + url: 'www.samd.org.cn', +}; diff --git a/lib/routes/samd/news.ts b/lib/routes/samd/news.ts new file mode 100644 index 000000000..07313d322 --- /dev/null +++ b/lib/routes/samd/news.ts @@ -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[], + }; + }, +};