diff --git a/lib/routes/swjtu/namespace.ts b/lib/routes/swjtu/namespace.ts index 0b500265ba346a..150a9a4c7a5b0c 100644 --- a/lib/routes/swjtu/namespace.ts +++ b/lib/routes/swjtu/namespace.ts @@ -2,6 +2,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: '西南交通大学', - url: 'ctt.swjtu.edu.cn', + url: 'www.swjtu.edu.cn', lang: 'zh-CN', }; diff --git a/lib/routes/swjtu/scai/bks.ts b/lib/routes/swjtu/scai.ts similarity index 59% rename from lib/routes/swjtu/scai/bks.ts rename to lib/routes/swjtu/scai.ts index 567680d30a7e24..2e76f8d936c240 100644 --- a/lib/routes/swjtu/scai/bks.ts +++ b/lib/routes/swjtu/scai.ts @@ -5,13 +5,12 @@ import { parseDate } from '@/utils/parse-date'; import ofetch from '@/utils/ofetch'; const rootURL = 'https://scai.swjtu.edu.cn'; -const pageURL = `${rootURL}/web/page-module.html?mid=B730BEB095B31840`; export const route: Route = { - path: '/scai/bks', + path: '/scai/:type', categories: ['university'], example: '/swjtu/scai/bks', - parameters: {}, + parameters: { type: '通知类型' }, features: { requireConfig: false, requirePuppeteer: false, @@ -26,11 +25,32 @@ export const route: Route = { }, ], name: '计算机与人工智能学院', - description: '本科生教育', + description: ` +| 分区 | 参数 | +| ----------------- | ----------- | +| 本科生教育 | bks | +| 研究生教育 | yjs | +| 学生工作 | xsgz | +`, maintainers: ['AzureG03', 'SuperJeason'], handler, }; +const partition = { + bks: { + title: '本科生教育', + url: `${rootURL}/web/page-module.html?mid=B730BEB095B31840`, + }, + yjs: { + title: '研究生教育', + url: `${rootURL}/web/page-module.html?mid=6A69B0E32021446B`, + }, + xsgz: { + title: '学生工作', + url: `${rootURL}/web/page-module.html?mid=F3D3909EB1861B5D`, + }, +}; + const getItem = (item, cache) => { const title = item.find('a').text(); const link = `${rootURL}${item.find('a').attr('href').slice(2)}`; @@ -39,22 +59,14 @@ const getItem = (item, cache) => { const res = await ofetch(link); const $ = load(res); - // 尝试获取日期 let dateText = $('div.news-info span:nth-of-type(2)').text(); + // 转教务通知时的时间获取方法 if (!dateText) { dateText = $('div.news-top-bar span:nth-of-type(1)').text(); } - if (!dateText) { - // console.error('Date not found for', link); - return null; // 或者返回一个默认值 - } - - const dateMatch = dateText.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/); - if (!dateMatch) { - // console.error('Invalid date format for', link); - return null; // 或者返回一个默认值 - } - const pubDate = parseDate(dateMatch[0]); + // 'date' may be undefined. and 'parseDate' will return current time. + const date = dateText.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)?.[0]; + const pubDate = parseDate(date); const description = $('div.content-main').html(); return { @@ -66,8 +78,10 @@ const getItem = (item, cache) => { }); }; -async function handler() { - const res = await ofetch(pageURL); +async function handler(ctx) { + const { type } = ctx.req.param(); + const url = partition[type].url; + const res = await ofetch(url); const $ = load(res); const $list = $('div.list-top-item, div.item-wrapper'); @@ -80,8 +94,8 @@ async function handler() { ); return { - title: '西南交大计算机学院-本科生教育', - link: pageURL, + title: `西南交大计院-${partition[type].title}`, + link: url, item: items, allowEmpty: true, }; diff --git a/lib/routes/swjtu/sports.ts b/lib/routes/swjtu/sports.ts new file mode 100644 index 00000000000000..8e8ef5dd265866 --- /dev/null +++ b/lib/routes/swjtu/sports.ts @@ -0,0 +1,77 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { ofetch } from 'ofetch'; + +const rootURL = 'https://sports.swjtu.edu.cn'; +const pageURL = `${rootURL}/xwzx.htm`; + +export const route: Route = { + path: '/sports', + categories: ['university'], + example: '/swjtu/sports', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['sports.swjtu.edu.cn/'], + }, + ], + name: '体育学院', + description: '新闻资讯', + maintainers: ['AzureG03'], + handler, +}; + +const getItem = (item, cache) => { + const title = item.find('p.toe').text(); + const link = `${rootURL}/${item.find('a').attr('href')}`; + + return cache.tryGet(link, async () => { + const res = await ofetch(link); + const $ = load(res); + + const pubDate = parseDate( + $('div.info span:nth-of-type(3)') + .text() + .slice(3) + .match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)?.[0] + ); + const description = $('div.detail-wrap').html(); + return { + title, + pubDate, + link, + description, + }; + }); +}; + +async function handler() { + const res = await ofetch(pageURL); + + const $ = load(res); + const $list = $('div.news-list > ul > li'); + + const items = await Promise.all( + $list.toArray().map((i) => { + const $item = $(i); + return getItem($item, cache); + }) + ); + + return { + title: '西南交大体院-新闻资讯', + link: pageURL, + item: items, + allowEmpty: true, + }; +}