Skip to content

Commit 05437e4

Browse files
authored
feat(route/zzu math & sxy): add math and business department route (#20970)
* feat(route/zzu math & sxy): add math and business department route - Add new route for Zhengzhou University School of Mathematics - Add new route for Zhengzhou University Business School * fix(zzu/sxy): 少量修复内容
1 parent 3feaff8 commit 05437e4

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

lib/routes/zzu/math.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { load } from 'cheerio';
2+
3+
import type { Route } from '@/types';
4+
import got from '@/utils/got';
5+
6+
export const route: Route = {
7+
path: '/math/:type',
8+
categories: ['university'],
9+
example: '/zzu/math/xyxw',
10+
parameters: { type: '分类名' },
11+
features: {
12+
requireConfig: false,
13+
requirePuppeteer: false,
14+
antiCrawler: false,
15+
supportBT: false,
16+
supportPodcast: false,
17+
supportScihub: false,
18+
},
19+
radar: [
20+
{
21+
source: ['www5.zzu.edu.cn/math/'],
22+
},
23+
],
24+
name: '郑大数学与统计学院',
25+
maintainers: ['amandus1990'],
26+
handler,
27+
description: `| 学院新闻 | 通知公告 | 党工团学 | 学术报告 |
28+
| -------- | -------- | -------- | -------- |
29+
| xyxw | tzgg | dgtx | xsbg |`,
30+
};
31+
32+
async function handler(ctx) {
33+
const type = ctx.req.param('type');
34+
const typeDict = {
35+
xyxw: ['学院新闻', 'https://www5.zzu.edu.cn/math/index/xyxw.htm'],
36+
tzgg: ['通知公告', 'https://www5.zzu.edu.cn/math/index/tzgg.htm'],
37+
dgtx: ['党工团学', 'https://www5.zzu.edu.cn/math/index/dgtx.htm'],
38+
xsbg: ['学术报告', 'https://www5.zzu.edu.cn/math/index/xsbg.htm'],
39+
};
40+
41+
// 获取页面内容
42+
const response = await got(typeDict[type][1]);
43+
const $ = load(response.data);
44+
45+
// 解析页面内容并提取文章信息
46+
const list = $('.text-list ul li')
47+
.toArray()
48+
.slice(0, 16)
49+
.map((element) => {
50+
const $element = $(element);
51+
const $link = $element.find('a').first();
52+
const link = new URL($link.attr('href'), typeDict[type][1]).href;
53+
const title = $link.attr('title') || $link.text().trim();
54+
55+
// 获取发布时间
56+
const pubDateText = $element.find('span').text().trim();
57+
58+
return {
59+
title,
60+
link,
61+
pubDate: pubDateText || null,
62+
};
63+
});
64+
65+
return {
66+
title: `郑大数学与统计学院-${typeDict[type][0]}`,
67+
link: typeDict[type][1],
68+
item: list,
69+
};
70+
}

lib/routes/zzu/sxy.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { load } from 'cheerio';
2+
3+
import type { Route } from '@/types';
4+
import got from '@/utils/got';
5+
6+
export const route: Route = {
7+
path: '/sxy/:type',
8+
categories: ['university'],
9+
example: '/zzu/sxy/xyxw',
10+
parameters: { type: '分类名' },
11+
features: {
12+
requireConfig: false,
13+
requirePuppeteer: false,
14+
antiCrawler: false,
15+
supportBT: false,
16+
supportPodcast: false,
17+
supportScihub: false,
18+
},
19+
radar: [
20+
{
21+
source: ['www5.zzu.edu.cn/sxy/'],
22+
},
23+
],
24+
name: '郑大商学院',
25+
maintainers: ['amandus1990'],
26+
handler,
27+
description: `| 学院新闻 | 通知公告 | 教学科研 | 党工团学 | 讲座报告 | 学者观点 |
28+
| -------- | -------- | -------- | -------- | -------- | -------- |
29+
| xyxw | tzgg | jxky | dgtx | jzbg | xzgd |`,
30+
};
31+
32+
async function handler(ctx) {
33+
const type = ctx.req.param('type');
34+
const typeDict = {
35+
xyxw: ['学院新闻', 'https://www5.zzu.edu.cn/sxy/index/xyxw.htm'],
36+
tzgg: ['通知公告', 'https://www5.zzu.edu.cn/sxy/index/tzgg.htm'],
37+
jxky: ['教学科研', 'https://www5.zzu.edu.cn/sxy/index/jxky.htm'],
38+
dgtx: ['党工团学', 'https://www5.zzu.edu.cn/sxy/index/dgtx.htm'],
39+
jzbg: ['讲座报告', 'https://www5.zzu.edu.cn/sxy/index/jzbg.htm'],
40+
xzgd: ['学者观点', 'https://www5.zzu.edu.cn/sxy/index/xzgd.htm'],
41+
};
42+
43+
// 获取页面内容
44+
const response = await got(typeDict[type][1]);
45+
const $ = load(response.data);
46+
47+
const list = type === 'xyxw' ? parseXyxwList($, typeDict, type) : parseOtherList($, typeDict, type);
48+
49+
return {
50+
title: `郑大商学院-${typeDict[type][0]}`,
51+
link: typeDict[type][1],
52+
item: list,
53+
};
54+
}
55+
56+
function parseXyxwList($, typeDict, type) {
57+
return $('section.n_titu ul li')
58+
.toArray()
59+
.slice(0, 6)
60+
.map((element) => {
61+
const $element = $(element);
62+
const $link = $element.find('a').first();
63+
const link = new URL($link.attr('href'), typeDict[type][1]).href;
64+
const title = $link.attr('title') || $link.text().trim();
65+
const description = $element.find('.right .con p').text().trim();
66+
67+
const monthDay = $element.find('.time_con h3').text().trim();
68+
const year = $element.find('.time_con h6').text().trim();
69+
const pubDateText = `${year}-${monthDay}`;
70+
71+
return {
72+
title,
73+
link,
74+
pubDate: pubDateText,
75+
description,
76+
};
77+
});
78+
}
79+
80+
function parseOtherList($, typeDict, type) {
81+
return $('.n_notice ul.ul li')
82+
.toArray()
83+
.slice(0, 16)
84+
.map((element) => {
85+
const $element = $(element);
86+
const $link = $element.find('a').first();
87+
const link = new URL($link.attr('href'), typeDict[type][1]).href;
88+
const title = $link.attr('title');
89+
90+
const pubDateText = $element.find('span.span01').text().trim();
91+
92+
return {
93+
title,
94+
link,
95+
pubDate: pubDateText || null,
96+
};
97+
});
98+
}

0 commit comments

Comments
 (0)