feat(route): 增加了国防科技大学研究生院中的硕士招生和通知公告的rss源 (#15589)

* feat: 增加了国防科技大学研究生院中的硕士招生和通知公告的rss源

* refactor(route): Update lib/routes/nudt/yjszs.ts
This commit is contained in:
tourist 2024-05-15 10:24:22 +08:00 committed by GitHub
parent 14e7761ef5
commit 1a6e8e1bbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '中国人民解放军国防科技大学',
url: 'www.nudt.edu.cn',
};

68
lib/routes/nudt/yjszs.ts Normal file
View File

@ -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: ['Blank0120'],
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,
};
}