diff --git a/lib/routes/gov/shenzhen/szlh/index.ts b/lib/routes/gov/shenzhen/szlh/index.ts new file mode 100644 index 000000000..2ff4df784 --- /dev/null +++ b/lib/routes/gov/shenzhen/szlh/index.ts @@ -0,0 +1,77 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import InvalidParameterError from '@/errors/types/invalid-parameter'; + +const config = { + tzgg: { + link: 'tzgg/', + title: '通知公告', + }, +}; + +export const route: Route = { + path: '/shenzhen/szlh/zwfw/zffw/:caty', + categories: ['government'], + example: '/gov/shenzhen/szlh/zwfw/zffw/tzgg', + parameters: { caty: '信息类别' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['szlh.gov.cn/zwfw/zffw/:caty'], + }, + ], + name: '深圳市罗湖区人民政府', + maintainers: ['lonn'], + handler, + description: `| 通知公告 | +| :------: | +| tzgg |`, +}; + +async function handler(ctx) { + const baseUrl = 'http://www.szlh.gov.cn/zwfw/zffw/'; + const cfg = config[ctx.req.param('caty')]; + if (!cfg) { + throw new InvalidParameterError('Bad category. See docs'); + } + + const currentUrl = new URL(cfg.link, baseUrl).href; + + const response = await ofetch(currentUrl); + const $ = load(response); + + const items = $('div.lists ul li') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a').first(); + + // Extract the date from + const date = a.find('i').text().trim(); + + // Clone and remove to get only the visible text + const textOnly = a.clone().find('i').remove().end().text().trim(); + + return { + title: textOnly, + link: a.attr('href'), + pubDate: timezone(parseDate(date, 'YYYY-MM-DD'), 0), + }; + }); + + return { + title: '深圳市罗湖区人民政府 - ' + cfg.title, + link: currentUrl, + item: items, + }; +} diff --git a/lib/routes/gov/shenzhen/szlh/namespace.ts b/lib/routes/gov/shenzhen/szlh/namespace.ts new file mode 100644 index 000000000..4fd24412f --- /dev/null +++ b/lib/routes/gov/shenzhen/szlh/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '深圳市罗湖区人民政府', + url: 'www.szlh.gov.cn', + categories: ['government'], + lang: 'zh-CN', +};