diff --git a/lib/routes/neu/yz.ts b/lib/routes/neu/yz.ts new file mode 100644 index 000000000..ece3c7cc6 --- /dev/null +++ b/lib/routes/neu/yz.ts @@ -0,0 +1,168 @@ +import { DataItem, Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const BASE_URL = 'http://yz.neu.edu.cn'; +const DOWNLOAD_ID = 5792; +const MASTER1_ID = 5932; +const MASTER2_ID = 5933; +const PhD1_ID = 5945; +const PhD2_ID = 5946; +const DOWNLOAD_AUTHOR = '研招办'; + +const idMp = { + download: DOWNLOAD_ID, + master1: MASTER1_ID, + master2: MASTER2_ID, + phd1: PhD1_ID, + phd2: PhD2_ID, +}; + +const parsePage = async (items, type) => { + const results = await Promise.all( + items.map(async (item) => { + const $ = load(item); + const aTag = $('span.Article_Title > a'); + const title = aTag.attr('title') ?? ""; + const url = BASE_URL + aTag.attr('href'); + const resultItem: DataItem = { + title, + link: url, + description: '', + pubDate: (() => { + const sTag = $('span.Article_PublishDate'); + const pubDate = sTag.text() ? timezone(parseDate(sTag.text()), +8) : undefined; + return pubDate; + })(), + author: type === DOWNLOAD_ID ? DOWNLOAD_AUTHOR : '', + }; + if (type === DOWNLOAD_ID && /\.(pdf|docx?|xlsx?|zip|rar|7z)$/i.test(url)) { + resultItem.description = ` +
${title}
点击进入文件传送门~:查看文件
+ ` + ); + }); + entry.find('.wp_video_player').each((_, el) => { + const div = $(el); + const src = div.attr('sudy-wp-src'); + if (src) { + const videoUrl = BASE_URL + src; + const widthMatch = div.attr('style')?.match(/width:\s*(\d+)px/); + const width = widthMatch && widthMatch[1] ? widthMatch[1] : '600'; + const heightMatch = div.attr('style')?.match(/height:\s*(\d+)px/); + const height = heightMatch && heightMatch[1] ? heightMatch[1] : '400'; + const videoTag = ` + + `; + div.replaceWith(videoTag); + } + }); + return entry.html(); +}; + +export const route: Route = { + path: '/yz/:type', + categories: ['university'], + example: '/neu/yz/master1', + parameters: { type: '分类id,见下表' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['yz.neu.edu.cn/:type/list.htm',], + target: '/yz/:type', + }, + ], + name: '研究生招生信息网', + url: 'yz.neu.edu.cn', + maintainers: ['paintstar'], + handler, + description: ` +| 分类名 | 分类id | +| ------------------------- | ---------- | +| 硕士公告 | master1 | +| 硕士简章 | master2 | +| 博士公告 | phd1 | +| 博士简章 | phd2 | +| 下载中心 | download |`, +};