/
news.ts
57 lines (53 loc) · 1.62 KB
/
news.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
const base_url = 'https://jw.dhu.edu.cn';
const map = {
student: '/tzggwxszl/list.htm',
teacher: '/tzggwjszl/list.htm',
};
export const route: Route = {
path: '/jiaowu/news/:type?',
categories: ['university'],
example: '/dhu/jiaowu/news/student',
parameters: { type: '默认为 `student`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '教务处通知',
maintainers: ['KiraKiseki'],
handler,
description: `| 学生专栏 | 教师专栏 |
| -------- | -------- |
| student | teacher |`,
};
async function handler(ctx) {
const type = ctx.req.param('type');
const link = Object.hasOwn(map, type) ? `${base_url}${map[type]}` : `${base_url}/tzggwxszl/list.htm`;
const response = await got({
method: 'get',
url: link,
headers: {
Referer: base_url,
},
});
const $ = load(response.data);
return {
link: base_url,
title: '东华大学教务处-' + $('.col_title').text(),
item: $('.list_item')
.map((_, elem) => ({
link: new URL($('a', elem).attr('href'), base_url),
title: $('a', elem).attr('title'),
pubDate: timezone(parseDate($('.Article_PublishDate', elem).text()), +8),
}))
.get(),
};
}