From 811d0ea96d3d0c7a8b215fb72fb04ff59aa30952 Mon Sep 17 00:00:00 2001 From: dengyj <17322619133@163.com> Date: Wed, 15 May 2024 01:10:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=9B=BD?= =?UTF-8?q?=E9=98=B2=E7=A7=91=E6=8A=80=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6?= =?UTF-8?q?=E7=94=9F=E9=99=A2=E4=B8=AD=E7=9A=84=E7=A1=95=E5=A3=AB=E6=8B=9B?= =?UTF-8?q?=E7=94=9F=E5=92=8C=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=E7=9A=84?= =?UTF-8?q?rss=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/nudt/namespace.ts | 6 ++++ lib/routes/nudt/yjszs.ts | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 lib/routes/nudt/namespace.ts create mode 100644 lib/routes/nudt/yjszs.ts diff --git a/lib/routes/nudt/namespace.ts b/lib/routes/nudt/namespace.ts new file mode 100644 index 00000000000000..d2743c4bf61df4 --- /dev/null +++ b/lib/routes/nudt/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '中国人民解放军国防科技大学', + url: 'www.nudt.edu.cn', +}; diff --git a/lib/routes/nudt/yjszs.ts b/lib/routes/nudt/yjszs.ts new file mode 100644 index 00000000000000..65beb13ebb935b --- /dev/null +++ b/lib/routes/nudt/yjszs.ts @@ -0,0 +1,68 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import InvalidParameterError from '@/errors/types/invalid-parameter'; +import timezone from '@/utils/timezone'; + +/* 研究生院*/ +const host = 'http://yjszs.nudt.edu.cn'; + +const yjszs = new Map([ + // http://yjszs.nudt.edu.cn//pubweb/homePageList/searchContent.view + ['tzgg', { title: '国防科技大学研究生院 - 通知公告', view: 'searchContent' }], + // http://yjszs.nudt.edu.cn//pubweb/homePageList/recruitStudents.view?keyId=16 + ['sszs', { title: '国防科技大学研究生院 - 硕士招生', view: 'recruitStudents', keyId: '16' }], +]); + +export const route: Route = { + path: '/yjszs/:type?', + categories: ['university'], + example: '/nudt/yjszs/sszs', + parameters: { type: '分类,见下表,默认为硕士招生' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '国防科技大学研究生院', + maintainers: ['blankTourist'], + handler, + url: 'yjszs.nudt.edu.cn/', + description: `| 通知公告 | 硕士招生 | + | -------- | -------- | + | tzgg | sszs |`, +}; + +async function handler(ctx) { + const type = ctx.req.param('type') ?? 'sszs'; + const info = yjszs.get(type); + if (!info) { + throw new InvalidParameterError('invalid type'); + } + const link = `${host}/pubweb/homePageList/${info.view}.view?keyId=${info.keyId ?? ''}`; + const response = await got({ + method: 'get', + url: link, + }); + + const $ = load(response.data); + const content = $('.news-list li'); + const items = content.toArray().map((elem) => { + elem = $(elem); + return { + link: new URL(elem.find('a').attr('href'), host).href, + title: elem.find('h3').text().trim(), + pubDate: timezone(parseDate(elem.find('.time').text(), 'YYYY-MM-DD'), -8), + }; + }); + + return { + title: info.title, + link, + item: items, + }; +}