From de263cbba0689f728b8779896dfa23f9e42f02fc Mon Sep 17 00:00:00 2001 From: 1200522928 <123849699+1200522928@users.noreply.github.com> Date: Tue, 12 Aug 2025 20:10:57 +0800 Subject: [PATCH] feat(route): add jwb of dgut (#19792) * Add files via upload * Add files via upload * Delete dgut directory * Add files via upload * style: auto format * Update jwb.ts * Add files via upload * style: auto format * Add files via upload * style: auto format * Update namespace.ts * Add files via upload * Update jwb.ts * Update lib/routes/dgut/jwb.ts Co-authored-by: Tony * Update lib/routes/dgut/jwb.ts Co-authored-by: Tony * Update lib/routes/dgut/jwb.ts Co-authored-by: Tony * Update lib/routes/dgut/namespace.ts Co-authored-by: Tony * Update jwb.ts --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/routes/dgut/jwb.ts | 73 ++++++++++++++++++++++++++++++++++++ lib/routes/dgut/namespace.ts | 9 +++++ 2 files changed, 82 insertions(+) create mode 100644 lib/routes/dgut/jwb.ts create mode 100644 lib/routes/dgut/namespace.ts diff --git a/lib/routes/dgut/jwb.ts b/lib/routes/dgut/jwb.ts new file mode 100644 index 000000000..336c3ed6f --- /dev/null +++ b/lib/routes/dgut/jwb.ts @@ -0,0 +1,73 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/jwb/:type?', + categories: ['university'], + example: '/dgut/jwb/jwtz', + parameters: { type: '哪种通知,默认为教务通知' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + maintainers: ['1200522928'], + radar: [ + { + source: ['jwb.dgut.edu.cn/tzgg/'], + target: '', + }, + ], + name: '教务部通知公告', + description: `| 教学动态 | 教务通知 | 教研通知 | 实践通知 | 产业学院 | 通识教育 |"杨振宁"班|招生信息 |采购公告 | +| ------- | ------- | ---------| --------| --------| ----------|---------|------- |--------| +| jxdt | jwtz | jytz | sjtz | cyxy | tsjy | yznb | zsxx | cggg |`, + handler, +}; + +async function handler(ctx) { + const { type = 'jwtz' } = ctx.req.param(); + const url = `https://jwb.dgut.edu.cn/tzgg/${type}.htm`; + const baseurl = 'https://jwb.dgut.edu.cn/'; + + const response = await ofetch(url); + const $ = load(response); + const list = $('ul.ul-new4 > li') + .toArray() + .map((item) => { + const $li = $(item); + const $a = $li.find('a.con'); + return { + title: $a.find('.tit').text().trim(), + pubDate: parseDate(`${$a.find('.year').text().trim()}-${$a.find('.day').text().trim()}`), + link: `${baseurl}${$a.attr('href')}`, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + + return { + ...item, + description: $('div.v_news_content').first().html() || undefined, + }; + }) + ) + ); + + return { + title: $('title').text(), + link: url, + allowEmpty: true, + item: items, + }; +} diff --git a/lib/routes/dgut/namespace.ts b/lib/routes/dgut/namespace.ts new file mode 100644 index 000000000..2dfc38cb2 --- /dev/null +++ b/lib/routes/dgut/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '东莞理工学院', + url: 'www.dgut.edu.cn', + zh: { + name: '东莞理工学院', + }, +};