From b777db44484ea61f63f7da2ca1daa065b40e85d2 Mon Sep 17 00:00:00 2001 From: ziri2004 <132821133+ziri2004@users.noreply.github.com> Date: Sun, 8 Jun 2025 22:51:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B7=BB=E5=8A=A0=E5=8C=97?= =?UTF-8?q?=E4=BA=AC=E9=82=AE=E7=94=B5=E5=A4=A7=E5=AD=A6=E7=BD=91=E5=AE=89?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=20(#19311)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts * Update scss.ts --- lib/routes/bupt/scss.ts | 98 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 lib/routes/bupt/scss.ts diff --git a/lib/routes/bupt/scss.ts b/lib/routes/bupt/scss.ts new file mode 100644 index 0000000000..2c3c86abec --- /dev/null +++ b/lib/routes/bupt/scss.ts @@ -0,0 +1,98 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/scss/tzgg', + categories: ['university'], + example: '/bupt/scss/tzgg', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['scss.bupt.edu.cn/index/tzgg1.htm'], + target: '/scss/tzgg', + }, + ], + name: '网络空间安全学院 - 通知公告', + maintainers: ['ziri2004'], + handler, + url: 'scss.bupt.edu.cn', +}; + +async function handler() { + const rootUrl = 'https://scss.bupt.edu.cn'; + const currentUrl = `${rootUrl}/index/tzgg1.htm`; + const pageTitle = '通知公告'; + const selector = '.Newslist li'; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = load(response.data); + const list = $(selector) + .toArray() + .map((item) => { + const $item = $(item); + const $link = $item.find('a'); + if ($link.length === 0 || !$link.attr('href')) { + return null; + } + + const link = new URL($link.attr('href'), rootUrl).href; + const rawDate = $item.find('span').text().replace('发布时间:', '').trim(); + + return { + title: $link.text().trim(), + link, + pubDateRaw: rawDate, + }; + }) + .filter(Boolean); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = load(detailResponse.data); + const newsContent = content('.v_news_content'); + + newsContent.find('p, span, strong').each(function () { + const element = content(this); + const text = element.text().trim(); + if (text === '') { + element.remove(); + } else { + element.replaceWith(text); + } + }); + + item.description = newsContent.text(); + item.pubDate = timezone(parseDate(item.pubDateRaw), +8); + + return item; + }) + ) + ); + + return { + title: `北京邮电大学网络空间安全学院 - ${pageTitle}`, + link: currentUrl, + item: items as Data['item'], + }; +}