/
jiaowu.ts
92 lines (84 loc) · 2.56 KB
/
jiaowu.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
// Yep http is bad, but I had no choice :(
const rootMeta = {
url: 'http://jiaowu.xaufe.edu.cn/',
title: '西安财经大学 教务处(招生办公室)',
};
const categories = {
tzgg: {
title: '通知公告',
url: 'index/tzgg.htm',
},
};
export const route: Route = {
path: '/jiaowu/:category?',
categories: ['university'],
example: '/xaufe/jiaowu/tzgg',
parameters: { category: '分类,默认为通知公告' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '教务处',
maintainers: ['shaokeyibb'],
handler,
description: `| 通知公告 |
| :------: |
| tzgg |`,
};
async function handler(ctx) {
const pCategory = ctx.req.param('category');
const category = categories[pCategory] || categories.tzgg;
const response = (
await got({
method: 'get',
url: rootMeta.url + category.url,
})
).body;
const $ = load(response);
const data = $('.main_conRCb ul li')
.slice(0, 16)
.toArray()
.map((item) => {
item = $(item);
const pubDate = item.children('span').text();
const title = item.find('a em').text();
const link = item.children('a').attr('href').replaceAll('../', rootMeta.url);
return {
pubDate: parseDate(pubDate),
title,
link,
};
});
return {
title: `${category.title}-${rootMeta.title}`,
link: rootMeta.url + category.url,
description: `${category.title}-${rootMeta.title}`,
language: 'zh_CN',
item: await Promise.all(
data.map((item) =>
cache.tryGet(item.link, async () => {
const $ = load(
(
await got({
method: 'get',
url: item.link,
})
).body
);
item.author = /作者:(\S*)\s{4}/g.exec($('p', '.main_contit').text())[1];
item.description = $('#vsb_content').html();
return item;
})
)
),
};
}