From 6b3af0bd21146ff63fde5edf0c5714c29ece1a91 Mon Sep 17 00:00:00 2001 From: Ke Xu Date: Wed, 22 Jan 2025 13:22:40 +0800 Subject: [PATCH] feat(route): Add /tongji/gs and Update /tongji/yjs (#18174) * Update /tongji/gs and /tongji/yjs * Replace text() with html() --- lib/routes/tongji/gs.ts | 66 ++++++++++++++++++++++++++++++++++++++++ lib/routes/tongji/yjs.ts | 54 ++++++++++++++++++++------------ 2 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 lib/routes/tongji/gs.ts diff --git a/lib/routes/tongji/gs.ts b/lib/routes/tongji/gs.ts new file mode 100644 index 00000000000000..4d1917344ce157 --- /dev/null +++ b/lib/routes/tongji/gs.ts @@ -0,0 +1,66 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/gs', + categories: ['university'], + example: '/tongji/gs', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['gs.tongji.edu.cn/tzgg.htm', 'gs.tongji.edu.cn/'], + }, + ], + name: '研究生院通知公告', + maintainers: ['sitdownkevin'], + handler, + url: 'gs.tongji.edu.cn/tzgg.htm', +}; + +async function getNoticeContent(item) { + const response = await got(item.link); + const $ = load(response.body); + const content = $('#vsb_content').html(); + item.description = content; + return item; +} + +async function handler() { + const baseUrl = 'https://gs.tongji.edu.cn'; + const response = await got(`${baseUrl}/tzgg.htm`); + const $ = load(response.body); + const container = $('body > div > div.con_list.ma0a > div > div.list_content_right > div.list_list > ul'); + const items = container + .find('li') + .toArray() + .map((item) => { + const title = $(item).find('a').attr('title'); + const linkRaw = $(item).find('a').attr('href'); + const link = linkRaw.startsWith('http') ? linkRaw : `${baseUrl}/${linkRaw}`; + const pubDate = $(item).find('span').text(); + return { title, link, pubDate: parseDate(pubDate, 'YYYY-MM-DD') }; + }); + + const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getNoticeContent(item)))); + + return { + title: '同济大学研究生院', + link: baseUrl, + description: '同济大学研究生院通知公告', + image: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + icon: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + logo: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + item: itemsWithContent, + }; +} diff --git a/lib/routes/tongji/yjs.ts b/lib/routes/tongji/yjs.ts index 63985774533852..afdfb0a013da70 100644 --- a/lib/routes/tongji/yjs.ts +++ b/lib/routes/tongji/yjs.ts @@ -2,6 +2,7 @@ import { Route } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; export const route: Route = { path: '/yjs', @@ -21,32 +22,45 @@ export const route: Route = { source: ['yz.tongji.edu.cn/zsxw/ggtz.htm', 'yz.tongji.edu.cn/'], }, ], - name: '研究生院通知公告', - maintainers: ['shengmaosu'], + name: '研究生招生网通知公告', + maintainers: ['shengmaosu', 'sitdownkevin'], handler, url: 'yz.tongji.edu.cn/zsxw/ggtz.htm', }; -async function handler() { - const link = 'https://yz.tongji.edu.cn/zsxw/ggtz.htm'; - const response = await got(link); +async function getNoticeContent(item) { + const response = await got(item.link); const $ = load(response.data); - const list = $('.list_main_content li'); + const content = $('#vsb_content').html(); + item.description = content; + return item; +} + +async function handler() { + const baseUrl = 'https://yz.tongji.edu.cn'; + const response = await got(`${baseUrl}/zsxw/ggtz.htm`); + const $ = load(response.body); + const container = $('#content-box > div.content > div.list_main_content > ul'); + const items = container + .find('li') + .toArray() + .map((item) => { + const title = $(item).find('a').attr('title'); + const linkRaw = $(item).find('a').attr('href'); + const link = linkRaw.startsWith('http') ? linkRaw : new URL(linkRaw, `${baseUrl}/zsxw`).toString(); + const pubDate = $(item).find('span').text(); + return { title, link, pubDate: parseDate(pubDate, 'YYYY-MM-DD') }; + }); + + const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getNoticeContent(item)))); return { - title: '同济大学研究生院', - link, - description: '同济大学研究生院通知公告', - item: - list && - list.toArray().map((item) => { - item = $(item); - const a = item.find('a'); - return { - title: a.attr('title'), - link: new URL(a.attr('href'), link).href, - pubDate: parseDate(item.find('span').text(), 'YYYY-MM-DD'), - }; - }), + title: '同济大学研究生招生网', + link: baseUrl, + description: '同济大学研究生招生网通知公告', + image: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + icon: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + logo: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg', + item: itemsWithContent, }; }