diff --git a/lib/routes/hdu/auto/graduate.ts b/lib/routes/hdu/auto/graduate.ts new file mode 100644 index 00000000000000..9dd10202979e01 --- /dev/null +++ b/lib/routes/hdu/auto/graduate.ts @@ -0,0 +1,27 @@ +import { Route } from '@/types'; +import { fetchAutoNews } from './utils'; + +export const route: Route = { + path: '/auto/graduate', + categories: ['university'], + example: '/hdu/auto/graduate', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '自动化学院 - 研究生教育通知', + maintainers: ['jalenzz'], + handler: () => fetchAutoNews('3754/list.htm', '研究生教育'), + description: '杭州电子科技大学自动化学院研究生教育', + radar: [ + { + source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3754/list.htm'], + target: '/auto/graduate', + }, + ], +}; diff --git a/lib/routes/hdu/auto/notice.ts b/lib/routes/hdu/auto/notice.ts new file mode 100644 index 00000000000000..610b1f20afb26b --- /dev/null +++ b/lib/routes/hdu/auto/notice.ts @@ -0,0 +1,27 @@ +import { Route } from '@/types'; +import { fetchAutoNews } from './utils'; + +export const route: Route = { + path: '/auto', + categories: ['university'], + example: '/hdu/auto', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '自动化学院 - 通知公告', + maintainers: ['jalenzz'], + handler: () => fetchAutoNews('3779/list.htm', '通知公告'), + description: '杭州电子科技大学自动化学院通知公告', + radar: [ + { + source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3779/list.htm'], + target: '/auto', + }, + ], +}; diff --git a/lib/routes/hdu/auto/student.ts b/lib/routes/hdu/auto/student.ts new file mode 100644 index 00000000000000..e38c6e65a730ba --- /dev/null +++ b/lib/routes/hdu/auto/student.ts @@ -0,0 +1,27 @@ +import { Route } from '@/types'; +import { fetchAutoNews } from './utils'; + +export const route: Route = { + path: '/auto/student', + categories: ['university'], + example: '/hdu/auto/student', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '自动化学院 - 学生工作', + maintainers: ['jalenzz'], + handler: () => fetchAutoNews('3726/list.htm', '学生工作'), + description: '杭州电子科技大学自动化学院学生工作', + radar: [ + { + source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3726/list.htm'], + target: '/auto/student', + }, + ], +}; diff --git a/lib/routes/hdu/auto/undergraduate.ts b/lib/routes/hdu/auto/undergraduate.ts new file mode 100644 index 00000000000000..07078ed75b1b8c --- /dev/null +++ b/lib/routes/hdu/auto/undergraduate.ts @@ -0,0 +1,27 @@ +import { Route } from '@/types'; +import { fetchAutoNews } from './utils'; + +export const route: Route = { + path: '/auto/undergraduate', + categories: ['university'], + example: '/hdu/auto/undergraduate', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '自动化学院 - 本科教学', + maintainers: ['jalenzz'], + handler: () => fetchAutoNews('3745/list.htm', '本科教学'), + description: '杭州电子科技大学自动化学院本科教学', + radar: [ + { + source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3745/list.htm'], + target: '/auto/undergraduate', + }, + ], +}; diff --git a/lib/routes/hdu/auto/utils.ts b/lib/routes/hdu/auto/utils.ts new file mode 100644 index 00000000000000..7dac71a24edca7 --- /dev/null +++ b/lib/routes/hdu/auto/utils.ts @@ -0,0 +1,51 @@ +import { Data, DataItem } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +const BASE_URL = 'https://auto.hdu.edu.cn'; + +export const fetchAutoNews = async (path: string, title: string): Promise => { + const link = `${BASE_URL}/${path}`; + const response = await got(link); + const $ = load(response.data); + + const list = $('.rightlist') + .toArray() + .map((item): DataItem => { + const $item = $(item); + const $a = $item.find('.newstitle a'); + const href = $a.attr('href'); + const title = $a.text().trim(); + const dateMatch = $item + .find('.newsinfo') + .text() + .match(/日期:(\d{4}\/\d{2}\/\d{2})/); + const brief = $item.find('.newsbrief').text().trim(); + + return { + title: title || '无标题', + link: href ? new URL(href, BASE_URL).href : BASE_URL, + pubDate: dateMatch ? parseDate(dateMatch[1], 'YYYY/MM/DD') : undefined, + description: brief || '', + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const { data } = await got(item.link); + const $detail = load(data); + const description = $detail('.wp_articlecontent').html(); + return { ...item, description: description || item.description }; + }) + ) + ); + + return { + title: `杭州电子科技大学自动化学院 - ${title}`, + link, + item: items as DataItem[], + }; +}; diff --git a/lib/routes/hdu/namespace.ts b/lib/routes/hdu/namespace.ts index 34d03d0b33b219..65eb985cc05b45 100644 --- a/lib/routes/hdu/namespace.ts +++ b/lib/routes/hdu/namespace.ts @@ -2,6 +2,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: '杭州电子科技大学', - url: 'computer.hdu.edu.cn', + url: 'hdu.edu.cn', lang: 'zh-CN', };