feat(route): add Northwest Normal University. (#18763)

* feat(route): add nwnu.

* fix: process embed PDF.

* chore: support 2738 param.

* fix: code styles, radars.

* feat: add academic affairs route.

* typo: fix.

* typo: fix
This commit is contained in:
但为君故
2025-04-04 17:33:14 +08:00
committed by GitHub
parent 605822d52d
commit 7dbb6ccfd7
5 changed files with 408 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '西北师范大学',
url: 'www.nwnu.edu.cn',
lang: 'zh-CN',
};
+133
View File
@@ -0,0 +1,133 @@
import NotFoundError from '@/errors/types/not-found';
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import { processEmbedPDF } from '../lib/embed-resource';
const WEBSITE_LOGO = 'https://jsj.nwnu.edu.cn/_upload/tpl/02/2e/558/template558/favicon.ico';
const BASE_URL = 'https://jsj.nwnu.edu.cn/';
const COLUMNS: Record<string, { title: string; description: string }> = {
'2435': {
title: '学院新闻',
description: '计算机科学与工程 学院新闻',
},
'2436': {
title: '通知公告',
description: '计算机科学与工程 通知公告',
},
'2437': {
title: '学术动态',
description: '计算机科学与工程 学术动态',
},
'2446': {
title: '研究生招生',
description: '计算机科学与工程学院 研究生招生动态及相关新闻',
},
'8411': {
title: '评估动态',
description: '计算机科学与工程学院 院系学科评估动态',
},
};
const handler: Route['handler'] = async (ctx) => {
const columnParam = ctx.req.param('column');
if (COLUMNS[columnParam] === undefined) {
throw new NotFoundError(`The column ${columnParam} does not exist`);
}
const columnTitle = COLUMNS[columnParam].title;
const columnDescription = COLUMNS[columnParam].description;
const columnPageUrl = `https://jsj.nwnu.edu.cn/${columnParam}/list.htm`;
// Fetch the list page
const { data: listResponse } = await got(columnPageUrl);
const $ = load(listResponse);
// Select all list items containing academic information
const ITEM_SELECTOR = 'ul > li.clearfix';
const listItems = $(ITEM_SELECTOR);
// Map through each list item to extract details
const itemLinks = listItems.toArray().map((element) => {
const title = $(element).find('div.right_list_text > p.p1 > a').text()!;
const imgRelativeLink = $(element).find('div.right_list_img > a > img').attr('src') || WEBSITE_LOGO;
const img = new URL(imgRelativeLink, BASE_URL).href;
const relativeHref = $(element).find('div.right_list_text > p.p1 > a').attr('href')!;
const link = new URL(relativeHref, BASE_URL).href;
return {
title,
img,
link,
};
});
return {
title: columnTitle,
description: columnDescription,
link: columnPageUrl,
image: WEBSITE_LOGO,
item: (await Promise.all(
itemLinks.map((item) =>
cache.tryGet(item.link, async () => {
const DATE_SELECTOR = 'div.sp2 > div > span:nth-child(1)';
const CONTENT_SELECTOR = 'div.artInfo';
const { data: contentResponse } = await got(item.link);
const contentPage = load(contentResponse);
const dateString = contentPage(DATE_SELECTOR).text();
const date = parseDate(dateString.replace('年', '-').replace('月', '-').replace('日', ''));
const content = processEmbedPDF(BASE_URL, contentPage(CONTENT_SELECTOR).html() || '');
return {
title: item.title,
pubDate: date,
link: item.link,
description: content,
category: ['university'],
guid: item.link,
id: item.link,
image: item.img,
content,
updated: date,
language: 'zh-CN',
};
})
)
)) as DataItem[],
allowEmpty: true,
language: 'zh-CN',
feedLink: `https://rsshub.app/nwnu/college/csse/${columnParam}`,
id: `https://rsshub.app/nwnu/college/csse/${columnParam}`,
};
};
export const route: Route = {
path: '/college/csse/:column',
name: '计算机科学与工程学院',
maintainers: ['PrinOrange'],
handler,
categories: ['university'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
example: '/college/csse/2435',
radar: [
{
source: ['jsj.nwnu.edu.cn/:column/list'],
target: '/college/csse/:column',
},
],
description: `
| column | 标题 | 描述 |
| ------ | ---------- | --------------------------------------------- |
| 2435 | 学院新闻 | 计算机科学与工程 学院新闻 |
| 2436 | 通知公告 | 计算机科学与工程 通知公告 |
| 2437 | 学术动态 | 计算机科学与工程 学术动态 |
| 2446 | 研究生招生 | 计算机科学与工程学院 研究生招生动态及相关新闻 |
| 8411 | 评估动态 | 计算机科学与工程学院 院系学科评估动态 |`,
};
@@ -0,0 +1,115 @@
import NotFoundError from '@/errors/types/not-found';
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import { processEmbedPDF } from '../lib/embed-resource';
const WEBSITE_LOGO = 'https://www.nwnu.edu.cn/_upload/tpl/02/d9/729/template729/favicon.ico';
const BASE_URL = 'https://jwc.nwnu.edu.cn/';
const COLUMNS: Record<string, { title: string; description: string }> = {
tzgg: {
title: '通知公告',
description: '西北师范大学教务处通知公告',
},
jwkx: {
title: '教务快讯',
description: '西北师范大学教务快讯',
},
};
const handler: Route['handler'] = async (ctx) => {
const columnParam = ctx.req.param('column');
if (COLUMNS[columnParam] === undefined) {
throw new NotFoundError(`The column ${columnParam} does not exist`);
}
const columnTitle = COLUMNS[columnParam].title;
const columnDescription = COLUMNS[columnParam].description;
const columnPageUrl = `https://jwc.nwnu.edu.cn/${columnParam}/list.htm`;
// Fetch the list page
const { data: listResponse } = await got(columnPageUrl);
const $ = load(listResponse);
// Select all list items containing academic information
const ITEM_SELECTOR = 'div.list_index > ul > li';
const listItems = $(ITEM_SELECTOR);
// Map through each list item to extract details
const itemLinks = listItems.toArray().map((element) => {
const title = $(element).find('span.f > a').text()!;
const date = parseDate($(element).find('span.r').text()!);
const relativeLink = $(element).find('span.f > a').attr('href')!;
const link = new URL(relativeLink, BASE_URL).href;
return {
title,
date,
link,
};
});
return {
title: columnTitle,
description: columnDescription,
link: columnPageUrl,
image: WEBSITE_LOGO,
item: (await Promise.all(
itemLinks.map((item) =>
cache.tryGet(item.link, async () => {
const CONTENT_SELECTOR = 'div.wp_articlecontent';
const { data: contentResponse } = await got(item.link);
const contentPage = load(contentResponse);
const content = processEmbedPDF(BASE_URL, contentPage(CONTENT_SELECTOR).html() || '');
return {
title: item.title,
pubDate: item.date,
link: item.link,
description: content,
category: ['university'],
guid: item.link,
id: item.link,
image: WEBSITE_LOGO,
content,
updated: item.date,
language: 'zh-CN',
};
})
)
)) as DataItem[],
allowEmpty: true,
language: 'zh-CN',
feedLink: `https://rsshub.app/nwnu/department/academic-affairs/${columnParam}`,
id: `https://rsshub.app/nwnu/department/academic-affairs/${columnParam}`,
};
};
export const route: Route = {
path: '/department/academic-affairs/:column',
name: '教务处',
maintainers: ['PrinOrange'],
handler,
categories: ['university'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportRadar: true,
supportPodcast: false,
supportScihub: false,
},
example: '/department/academic-affairs/tzgg',
radar: [
{
source: ['jwc.nwnu.edu.cn/:column/list.htm'],
target: '/department/academic-affairs/:column',
},
],
description: `
| column | 标题 | 描述 |
| ------ | -------- | ------------------------ |
| tzgg | 通知公告 | 西北师范大学教务通知公告 |
| jwkx | 教务快讯 | 西北师范大学教务快讯 |`,
};
@@ -0,0 +1,139 @@
import NotFoundError from '@/errors/types/not-found';
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import { processEmbedPDF } from '../lib/embed-resource';
const WEBSITE_LOGO = 'https://www.nwnu.edu.cn/_upload/tpl/02/d9/729/template729/favicon.ico';
const BASE_URL = 'https://yjsy.nwnu.edu.cn/';
const COLUMNS: Record<string, { title: string; description: string }> = {
'2701': {
title: '招生工作(包括硕士、博士招生)',
description: '研究生院招生信息(包含硕士招生和博士招生两个栏目)',
},
'2738': {
title: '工作动态',
description: '研究生院工作动态',
},
'2712': {
title: '博士招生',
description: '研究生院博士研究生招生信息',
},
'2713': {
title: '硕士招生',
description: '研究生院硕士研究生招生信息',
},
'2702': {
title: '培养工作',
description: '培养工作栏目信息汇总',
},
'2703': {
title: '学科建设',
description: '研究生院学科建设信息汇总',
},
'2704': {
title: '学位工作',
description: '研究生院学位工作栏目信息汇总',
},
};
const handler: Route['handler'] = async (ctx) => {
const columnParam = ctx.req.param('column');
if (COLUMNS[columnParam] === undefined) {
throw new NotFoundError(`The column ${columnParam} does not exist`);
}
const columnTitle = COLUMNS[columnParam].title;
const columnDescription = COLUMNS[columnParam].description;
const columnPageUrl = `https://yjsy.nwnu.edu.cn/${columnParam}/list.htm`;
// Fetch the list page
const { data: listResponse } = await got(columnPageUrl);
const $ = load(listResponse);
// Select all list items containing academic information
const ITEM_SELECTOR = '#AjaxList > ul > li.a-list';
const listItems = $(ITEM_SELECTOR);
// Map through each list item to extract details
const itemLinks = listItems.toArray().map((element) => {
const title = $(element).find('a:nth-child(2)').attr('title')!;
const date = parseDate($(element).find('span.pdate').text()!);
const relativeLink = $(element).find('a:nth-child(2)').attr('href')!;
const link = new URL(relativeLink, BASE_URL).href;
return {
title,
date,
link,
};
});
return {
title: columnTitle,
description: columnDescription,
link: columnPageUrl,
image: WEBSITE_LOGO,
item: (await Promise.all(
itemLinks.map((item) =>
cache.tryGet(item.link, async () => {
const CONTENT_SELECTOR = 'div.content_div';
const { data: contentResponse } = await got(item.link);
const contentPage = load(contentResponse);
const content = processEmbedPDF(BASE_URL, contentPage(CONTENT_SELECTOR).html() || '');
return {
title: item.title,
pubDate: item.date,
link: item.link,
description: content,
category: ['university'],
guid: item.link,
id: item.link,
image: WEBSITE_LOGO,
content,
updated: item.date,
language: 'zh-CN',
};
})
)
)) as DataItem[],
allowEmpty: true,
language: 'zh-CN',
feedLink: `https://rsshub.app/nwnu/department/postgraduate/${columnParam}`,
id: `https://rsshub.app/nwnu/department/postgraduate/${columnParam}`,
};
};
export const route: Route = {
path: '/department/postgraduate/:column',
name: '研究生院',
maintainers: ['PrinOrange'],
handler,
categories: ['university'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportRadar: true,
supportPodcast: false,
supportScihub: false,
},
example: '/department/postgraduate/2701',
radar: [
{
source: ['yjsy.nwnu.edu.cn/:column/list.htm'],
target: '/department/postgraduate/:column',
},
],
description: `
| column | 标题 | 描述 |
| ------ | ------------------------------ | -------------------------------------------------- |
| 2701 | 招生工作(包括硕士、博士招生) | 研究生院招生信息(包含硕士招生和博士招生两个栏目) |
| 2712 | 博士招生 | 研究生院博士研究生招生信息 |
| 2713 | 硕士招生 | 研究生院硕士研究生招生信息 |
| 2702 | 培养工作 | 培养工作栏目信息汇总 |
| 2703 | 学科建设 | 研究生院学科建设信息汇总 |
| 2704 | 学位工作 | 研究生院学位工作栏目信息汇总 |`,
};
@@ -0,0 +1,14 @@
import { load } from 'cheerio';
export function processEmbedPDF(baseurl: string, html: string) {
const $ = load(html);
$('div.wp_pdf_player').each(function () {
const $div = $(this);
const pdfsrc = $div.attr('pdfsrc') || '';
const downloadUrl = new URL(pdfsrc, baseurl).href;
const newDiv = `<p><a href=${downloadUrl} target="_blank">点击下载 PDF 文件资源</a></p>`;
$div.replaceWith(newDiv);
});
return $.html();
}