From d6fd26238e8f0396e0020513a12a85b6013fabb9 Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Sat, 21 Dec 2024 03:38:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B7=BB=E5=8A=A0=20=E6=B5=B7?= =?UTF-8?q?=E5=8D=97=E7=9C=81=E5=B7=A5=E4=B8=9A=E5=92=8C=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=8C=96=E5=8E=85-=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#179?= =?UTF-8?q?23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 添加 海南省工业和信息化厅-通知公告 * fix: add namespace --------- --- lib/routes/gov/hainan/iitb/tzgg.ts | 77 ++++++++++++++++++++++++++++++ lib/routes/gov/hainan/namespace.ts | 8 ++++ 2 files changed, 85 insertions(+) create mode 100644 lib/routes/gov/hainan/iitb/tzgg.ts create mode 100644 lib/routes/gov/hainan/namespace.ts diff --git a/lib/routes/gov/hainan/iitb/tzgg.ts b/lib/routes/gov/hainan/iitb/tzgg.ts new file mode 100644 index 00000000000000..a071279a01f384 --- /dev/null +++ b/lib/routes/gov/hainan/iitb/tzgg.ts @@ -0,0 +1,77 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/hainan/iitb/tzgg', + categories: ['government'], + example: '/gov/hainan/iitb/tzgg', + url: 'iitb.hainan.gov.cn/iitb/tzgg/list2.shtml', + name: '通知公告', + maintainers: ['p3psi-boo'], + handler, +}; + +async function handler() { + // The TLS cert is invalid, we are limited to use HTTP unfortunately. + const baseUrl = 'https://iitb.hainan.gov.cn'; + const targetUrl = `${baseUrl}/iitb/tzgg/list2.shtml`; + + const response = await got({ + method: 'get', + url: targetUrl, + }); + + const $ = load(response.data); + + const alist = $('.list_div'); + + const list = alist.toArray().map((item) => { + const elem = $(item); + + const titleElement = elem.find('.list-right_title a'); + const link = titleElement.attr('href') || ''; + const title = titleElement.text().trim() || ''; + const dateText = elem.find('td[align="left"]').text().replace('发布时间:', '').trim(); + const department = elem.find('.column-name').text().trim(); + + return { + title, + link: new URL(link, baseUrl).href, + pubDate: parseDate(dateText), + category: department, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + }); + + const $ = load(response.data); + + const author = $('#xxgkfbjg').text(); + const pubDate = $('publishtime').text(); + const content = $('ucapcontent').html(); + + item.author = author; + item.pubDate = parseDate(pubDate); + item.description = content; + + return item; + }) + ) + ); + + return { + title: '通知公告 - 海南省工业和信息化厅', + link: targetUrl, + item: items, + }; +} diff --git a/lib/routes/gov/hainan/namespace.ts b/lib/routes/gov/hainan/namespace.ts new file mode 100644 index 00000000000000..858efdc77587d4 --- /dev/null +++ b/lib/routes/gov/hainan/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '海南省人民政府', + url: 'hainan.gov.cn', + categories: ['government'], + lang: 'zh-CN', +};