From 2a8c685da9113e37e3e4267cdacbae5490b6b5b6 Mon Sep 17 00:00:00 2001 From: yoghurt <41856917+YoghurtGuy@users.noreply.github.com> Date: Wed, 12 Mar 2025 03:46:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=A5=BF=E5=AE=89?= =?UTF-8?q?=E4=BA=A4=E9=80=9A=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6=E7=94=9F?= =?UTF-8?q?=E6=8B=9B=E7=94=9F=E4=BF=A1=E6=81=AF=E7=BD=91=20(#18561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 西安交通大学研究生招生信息网 * fix(route/xjtu): improve description without spaces, type safety and radar's URL handling * fix(route/xjtu): remove unnecessary filter --- lib/routes/xjtu/yz.ts | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lib/routes/xjtu/yz.ts diff --git a/lib/routes/xjtu/yz.ts b/lib/routes/xjtu/yz.ts new file mode 100644 index 000000000..2082d2628 --- /dev/null +++ b/lib/routes/xjtu/yz.ts @@ -0,0 +1,74 @@ +import type { Data, DataItem, Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; +import logger from '@/utils/logger'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/yz/:category?', + categories: ['university'], + example: '/xjtu/yz/zsdt', + parameters: { category: '栏目类型,默认请求`zsdt`,详见下方表格' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['yz.xjtu.edu.cn/index/:category.htm'], + target: '/yz/:category', + }, + ], + name: '研究生招生信息网', + maintainers: ['YoghurtGuy'], + handler, + description: `栏目类型 + +| 招生动态 | 通知公告 | 政策法规 | 招生统计 | 历年复试线 | 博士招生 | 硕士招生 | 推免生 | 其他招生 | +| -------- | -------- | -------- | -------- | ---------- | -------- | -------- | ------ | -------- | +| zsdt | tzgg | zcfg | zstj | lnfsx | bszs | sszs | tms | qtzs |`, +}; +async function handler(ctx) { + const { category = 'zsdt' } = ctx.req.param(); + const baseUrl = 'https://yz.xjtu.edu.cn'; + + const response = await ofetch(`${baseUrl}/index/${category}.htm`); + const $ = load(response); + const list = $('div.list-con ul li') + .toArray() + .map((item_) => { + const item = $(item_); + const a = item.find('a'); + return { + title: a.attr('title'), + link: new URL(a.attr('href')!, baseUrl).href, + pubDate: timezone(parseDate(item.find('span.date.fr').text()), +8), + } as DataItem; + }); + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link!, async () => { + try { + const res = await ofetch(item.link!); + const content = load(res); + item.description = content('#vsb_content').html()! + (content('form ul').length > 0 ? content('form ul').html() : ''); + return item; + } catch (error) { + logger.error(`Fetch failed for ${item.link}:`, error); + return item; + } + }) + ) + ); + return { + title: '西安交通大学研究生招生信息网', + link: 'https://yz.xjtu.edu.cn', + item: items, + } as Data; +}