From a06670eff5248b474b200f60649daa5b296b854f Mon Sep 17 00:00:00 2001 From: AzureG03 <155449067+AzureG03@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:54:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=A5=BF=E5=8D=97?= =?UTF-8?q?=E4=BA=A4=E9=80=9A=E5=A4=A7=E5=AD=A6=E8=AE=A1=E7=AE=97=E6=9C=BA?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E6=9C=AC=E7=A7=91=E7=94=9F=E6=95=99=E8=82=B2?= =?UTF-8?q?=20(#16810)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 西南交通大学计算机学院本科生教育 * Update lib/routes/swjtu/scai/bks.ts --- lib/routes/swjtu/scai/bks.ts | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/routes/swjtu/scai/bks.ts diff --git a/lib/routes/swjtu/scai/bks.ts b/lib/routes/swjtu/scai/bks.ts new file mode 100644 index 0000000000000..af442a576c01b --- /dev/null +++ b/lib/routes/swjtu/scai/bks.ts @@ -0,0 +1,80 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { ofetch } from 'ofetch'; + +const rootURL = 'https://scai.swjtu.edu.cn'; +const pageURL = `${rootURL}/web/page-module.html?mid=B730BEB095B31840`; + +export const route: Route = { + path: '/scai/bks', + categories: ['university'], + example: '/swjtu/scai/bks', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['scai.swjtu.edu.cn/'], + }, + ], + name: '计算机与人工智能学院', + description: '本科生教育', + maintainers: ['AzureG03'], + handler, +}; + +const getItem = (item, cache) => { + const title = item.find('a').text(); + const link = `${rootURL}${item.find('a').attr('href').slice(2)}`; + + return cache.tryGet(link, async () => { + const res = await ofetch(link); + const $ = load(res); + + const pubDate = parseDate( + $('div.news-info span:nth-of-type(2)') + .text() + .match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)[0] + ); + const description = $('div.content-main').html(); + return { + title, + pubDate, + link, + description, + }; + }); +}; + +async function handler() { + const res = await got({ + method: 'get', + url: pageURL, + }); + + const $ = load(res.data); + const $list = $('div.list-top-item, div.item-wrapper'); + + const items = await Promise.all( + $list.toArray().map((i) => { + const $item = $(i); + return getItem($item, cache); + }) + ); + + return { + title: '西南交大计算机学院-本科生教育', + link: pageURL, + item: items, + allowEmpty: true, + }; +}