From e455fe7bb6f8482294156879e748538af4c820aa Mon Sep 17 00:00:00 2001 From: Hualiang <78242797+hualiong@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:15:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(routes):=20=E6=96=B0=E5=A2=9E=E6=B7=B1?= =?UTF-8?q?=E5=9C=B3=E5=B8=82=E5=8C=BB=E7=96=97=E5=99=A8=E6=A2=B0=E8=A1=8C?= =?UTF-8?q?=E4=B8=9A=E5=8D=8F=E4=BC=9A=E5=92=8C=E4=B8=AD=E5=9B=BD=E9=A3=9F?= =?UTF-8?q?=E5=93=81=E5=9C=9F=E7=95=9C=E8=BF=9B=E5=87=BA=E5=8F=A3=E5=95=86?= =?UTF-8?q?=E4=BC=9A=20(#15964)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(routes): 新增深圳市医疗器械行业协会和中国食品土畜进出口商会 * Update lib/routes/cccfna/index.ts Co-authored-by: Tony * Update lib/routes/samd/news.ts Co-authored-by: Tony * update --------- --- lib/routes/cccfna/index.ts | 82 ++++++++++++++++++++++++++++++++++ lib/routes/cccfna/namespace.ts | 6 +++ lib/routes/samd/namespace.ts | 6 +++ lib/routes/samd/news.ts | 74 ++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 lib/routes/cccfna/index.ts create mode 100644 lib/routes/cccfna/namespace.ts create mode 100644 lib/routes/samd/namespace.ts create mode 100644 lib/routes/samd/news.ts 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[], + }; + }, +};