From 95a5e5025464fa7a523231b5edfbd696cf7ee95f Mon Sep 17 00:00:00 2001 From: LMark <40017222+ladeng07@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:55:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20Add=20=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E5=B8=88=E8=8C=83=E5=A4=A7=E5=AD=A6=E6=95=99=E5=8A=A1=E9=83=A8?= =?UTF-8?q?=20(#14959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/bnu/jwb.ts | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/routes/bnu/jwb.ts diff --git a/lib/routes/bnu/jwb.ts b/lib/routes/bnu/jwb.ts new file mode 100644 index 000000000..5d190eeac --- /dev/null +++ b/lib/routes/bnu/jwb.ts @@ -0,0 +1,56 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/jwb', + categories: ['university'], + example: '/bnu/jwb', + parameters: {}, + radar: [ + { + source: ['jwb.bnu.edu.cn'], + }, + ], + name: '教务部(研究生院)', + maintainers: ['ladeng07'], + handler, + url: 'jwb.bnu.edu.cn/tzgg/index.htm', +}; + +async function handler() { + const link = 'https://jwb.bnu.edu.cn/tzgg/index.htm'; + const response = await got(link); + const $ = load(response.data); + const list = $('.article-list .boxlist ul li') + .toArray() + .map((e) => { + e = $(e); + const a = e.find('a'); + return { + title: e.find('a span').text(), + link: a.attr('href').startsWith('http') ? a.attr('href') : 'https://jwb.bnu.edu.cn' + a.attr('href').substring(2), + pubDate: parseDate(e.find('span.fr.text-muted').text(), 'YYYY-MM-DD'), + }; + }); + + const out = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = load(response.data); + item.author = '北京师范大学教务部'; + item.description = $('.contenttxt').html(); + return item; + }) + ) + ); + + return { + title: '北京师范大学教务部', + link, + description: '北京师范大学教务部最新通知', + item: out, + }; +}