From 98affee3cd356b9a027e996c348d6794ce1f1813 Mon Sep 17 00:00:00 2001 From: gdzhht <48609520+gdzhht@users.noreply.github.com> Date: Tue, 27 Aug 2024 01:16:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=20=E5=8D=8E?= =?UTF-8?q?=E5=8D=97=E7=90=86=E5=B7=A5=E5=A4=A7=E5=AD=A6=E5=B9=BF=E5=B7=9E?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E6=A0=A1=E5=8C=BA=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E3=80=81=E6=96=B0=E9=97=BB=E8=81=9A=E7=84=A6=E3=80=81?= =?UTF-8?q?=E5=AA=92=E4=BD=93=E6=8A=A5=E9=81=93=20=E8=B7=AF=E7=94=B1=20(#1?= =?UTF-8?q?6372)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 新增 华南理工大学广州国际校区通知公告、新闻聚焦、媒体报道 路由 * 遵循路由规范 * Update lib/routes/scut/gzic/news.ts --------- --- lib/routes/scut/gzic/media.ts | 71 +++++++++++++++++++++++++++ lib/routes/scut/gzic/news.ts | 65 +++++++++++++++++++++++++ lib/routes/scut/gzic/notice.ts | 88 ++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 lib/routes/scut/gzic/media.ts create mode 100644 lib/routes/scut/gzic/news.ts create mode 100644 lib/routes/scut/gzic/notice.ts diff --git a/lib/routes/scut/gzic/media.ts b/lib/routes/scut/gzic/media.ts new file mode 100644 index 0000000000000..4e8dcfd0bc394 --- /dev/null +++ b/lib/routes/scut/gzic/media.ts @@ -0,0 +1,71 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import ofetch from '@/utils/ofetch'; + +export const route: Route = { + path: '/gzic/media', + categories: ['university'], + example: '/scut/gzic/media', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '广州国际校区 - 媒体报道', + maintainers: ['gdzhht'], + handler, + description: `:::warning +由于学校网站对非大陆 IP 的访问存在限制,可能需自行部署。 +:::`, +}; + +async function handler() { + const url = 'https://www2.scut.edu.cn/gzic/30281/list.htm'; + + const { data: response } = await got(url); + const $ = load(response); + + const list = $('.right-nr .row .col-lg-4') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('.thr-box a'); + const pubDate = item.find('.thr-box a span'); + return { + title: item.find('.thr-box a p').text(), + link: a.attr('href')?.startsWith('http') ? a.attr('href') : `https://www2.scut.edu.cn${a.attr('href')}`, + pubDate: parseDate(pubDate.text()), + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + try { + const response = await ofetch(item.link); + const $ = load(response); + item.description = $('div.wp_articlecontent').html(); + } catch (error) { + if (error.response && error.response.status === 404) { + item.description = ''; + } else { + throw error; + } + } + return item; + }) + ) + ); + + return { + title: '华南理工大学广州国际校区 - 媒体报道', + link: url, + item: items, + }; +} diff --git a/lib/routes/scut/gzic/news.ts b/lib/routes/scut/gzic/news.ts new file mode 100644 index 0000000000000..766976aba3a54 --- /dev/null +++ b/lib/routes/scut/gzic/news.ts @@ -0,0 +1,65 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import ofetch from '@/utils/ofetch'; + +export const route: Route = { + path: '/gzic/news', + categories: ['university'], + example: '/scut/gzic/news', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '广州国际校区 - 新闻聚焦', + maintainers: ['gdzhht'], + handler, + description: `:::warning +由于学校网站对非大陆 IP 的访问存在限制,可能需自行部署。 +:::`, +}; + +async function handler() { + const baseUrl = 'https://www2.scut.edu.cn'; + const url = 'https://www2.scut.edu.cn/gzic/30279/list.htm'; + + const { data: response } = await got(url); + const $ = load(response); + + const list = $('.right-nr .row .col-lg-4') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('.li-img a'); + const pubDate = item.find('.li-img a span'); + return { + title: item.find('.li-img a p').text(), + link: a.attr('href')?.startsWith('http') ? a.attr('href') : `${baseUrl}${a.attr('href')}`, + pubDate: parseDate(pubDate.text().replaceAll(/年|月/g, '-').replaceAll('日', '')), + itunes_item_image: `${baseUrl}${item.find('.li-img img').attr('src')}`, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + item.description = item.link.startsWith('https://mp.weixin.qq.com/') ? $('div.rich_media_content section').html() : $('div.wp_articlecontent').html(); + return item; + }) + ) + ); + + return { + title: '华南理工大学广州国际校区 - 新闻聚焦', + link: url, + item: items, + }; +} diff --git a/lib/routes/scut/gzic/notice.ts b/lib/routes/scut/gzic/notice.ts new file mode 100644 index 0000000000000..d98a264bcd9ff --- /dev/null +++ b/lib/routes/scut/gzic/notice.ts @@ -0,0 +1,88 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import ofetch from '@/utils/ofetch'; + +const categoryMap = { + xsyg: { title: '学术预告', tag: '30284' }, + jytz: { title: '教研通知', tag: '30307' }, + hwxx: { title: '海外学习', tag: 'hwxx' }, + swtz: { title: '事务通知', tag: '30283' }, +}; + +export const route: Route = { + path: '/gzic/notice/:category?', + categories: ['university'], + example: '/scut/gzic/notice/swtz', + parameters: { category: '通知分类,默认为 `swtz`' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '广州国际校区 - 通知公告', + maintainers: ['gdzhht'], + handler, + description: `| 学术预告 | 教研通知 | 海外学习 | 事务通知 | + | -------- | -------- | -------- | -------- | + | xsyg | jytz | hwxx | swtz | + +:::warning +由于学校网站对非大陆 IP 的访问存在限制,可能需自行部署。 +部分通知详情页可能会被删除(返回 404),或在校园网外无法访问。 +:::`, +}; + +async function handler(ctx) { + const baseUrl = 'https://www2.scut.edu.cn'; + + const categoryName = ctx.req.param('category') || 'swtz'; + const categoryMeta = categoryMap[categoryName]; + const url = `${baseUrl}/gzic/${categoryMeta.tag}/list.htm`; + + const { data: response } = await got(url); + const $ = load(response); + + const list = $('.right-nr .row .col-lg-4') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('.thr-box a'); + const pubDate = item.find('.thr-box a span'); + return { + title: item.find('.thr-box a p').text(), + link: a.attr('href')?.startsWith('http') ? a.attr('href') : `${baseUrl}${a.attr('href')}`, + pubDate: parseDate(pubDate.text()), + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + try { + const response = await ofetch(item.link); + const $ = load(response); + item.description = $('div.wp_articlecontent').html(); + } catch (error) { + if (error.response && error.response.status === 404) { + item.description = ''; + } else { + throw error; + } + } + return item; + }) + ) + ); + + return { + title: `华南理工大学广州国际校区 - ${categoryMeta.title}`, + link: url, + item: items, + }; +}