From 46086571b91b0c1ad41e35aab583cfe939f67caf Mon Sep 17 00:00:00 2001 From: FrozenStar Date: Wed, 19 Nov 2025 21:57:07 +0800 Subject: [PATCH] feat(route): add East China Normal University Undergraduate Office notice (#20515) * feat(route): add East China Normal University Undergraduate Office notices Co-authored-by: Yuki Chiyo * fix(route): delete a useless option and modified outdated url Co-authored-by: Yuki Chiyo --------- Co-authored-by: Yuki Chiyo --- lib/routes/ecnu/bksy.ts | 63 ++++++++++++++++++++++++++++++++++++ lib/routes/ecnu/namespace.ts | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 lib/routes/ecnu/bksy.ts diff --git a/lib/routes/ecnu/bksy.ts b/lib/routes/ecnu/bksy.ts new file mode 100644 index 000000000..9265d99be --- /dev/null +++ b/lib/routes/ecnu/bksy.ts @@ -0,0 +1,63 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const type = (filename) => filename.split('.').pop(); + +export const route: Route = { + path: '/bksy', + categories: ['university'], + example: '/ecnu/bksy', + radar: [ + { + source: ['bksy.ecnu.edu.cn'], + target: '/tzgg', + }, + ], + name: '本科生院通知', + maintainers: ['ChiyoYuki', 'FrozenStarrrr'], + handler: async () => { + const baseUrl = 'https://bksy.ecnu.edu.cn/'; + + const response = await got(`${baseUrl}tzggwwxsgg/list.htm`); + const $ = load(response.data); + const links = $('ul.news_list.list2 > li') + .toArray() + .map((el) => ({ + pubDate: timezone(parseDate($(el).find('.news_date').text()), 8), + link: new URL($(el).find('a').attr('href'), baseUrl).toString(), + title: $(el).find('a').text(), + })); + const items = await Promise.all( + links.map((item) => + cache.tryGet(item.link, async () => { + if (type(item.link) === 'htm') { + try { + const { data } = await got(item.link); + const $ = load(data); + item.description = $('div.article')?.html()?.replaceAll('src="/', `src="${baseUrl}/`)?.replaceAll('href="/', `href="${baseUrl}/`)?.trim(); + return item; + } catch { + // intranet + item.description = '请进行统一身份认证之后再访问'; + return item; + } + } else { + // file to download + item.description = '点击认证后访问内容'; + return item; + } + }) + ) + ); + + return { + title: '本科生院通知', + link: 'https://bksy.ecnu.edu.cn/tzggwwxsgg/list.htm', + item: items, + }; + }, +}; diff --git a/lib/routes/ecnu/namespace.ts b/lib/routes/ecnu/namespace.ts index 19c34ac77..59b4f380c 100644 --- a/lib/routes/ecnu/namespace.ts +++ b/lib/routes/ecnu/namespace.ts @@ -2,6 +2,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'East China Normal University 华东师范大学', - url: 'ecnu.edu.cn', + url: 'www.ecnu.edu.cn', lang: 'zh-CN', };