/
zbb.ts
101 lines (91 loc) · 3.18 KB
/
zbb.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
93
94
95
96
97
98
99
100
101
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export const route: Route = {
path: '/zbb/:type',
categories: ['university'],
example: '/nju/zbb/cgxx',
parameters: { type: '分类名' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '招标办公室',
maintainers: ['ret-1'],
handler,
description: `| 采购信息 | 成交公示 | 政府采购意向公开 |
| -------- | -------- | ---------------- |
| cgxx | cjgs | zfcgyxgk |`,
};
async function handler(ctx) {
const type = ctx.req.param('type');
if (type === 'zfcgyxgk') {
const url = `https://zbb.nju.edu.cn/zfcgyxgk/index.chtml`;
const response = await got({
method: 'get',
url,
});
const data = response.data;
const $ = load(data);
const list = $('dd[cid]');
return {
title: '政府采购意向公开',
link: url,
item: list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
description: item.find('a').first().text(),
link: 'https://zbb.nju.edu.cn' + item.find('a').attr('href'),
pubDate: timezone(parseDate(item.find('span').first().text(), 'YYYY-MM-DD'), +8),
};
})
.get(),
};
} else {
const title_dict = {
cgxx: '采购信息',
cjgs: '成交公示',
};
const category_dict = {
hw: '货物类',
gc: '工程类',
fw: '服务类',
};
const items = await Promise.all(
Object.keys(category_dict).map(async (c) => {
const response = await got({
method: 'get',
url: `https://zbb.nju.edu.cn/${type}${c}/index.chtml`,
});
const data = response.data;
const $ = load(data);
const list = $('dd[cid]');
return list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
description: item.find('a').first().text(),
link: 'https://zbb.nju.edu.cn' + item.find('a').attr('href'),
pubDate: timezone(parseDate(item.find('span').first().text(), 'YYYY-MM-DD'), +8),
category: category_dict[c],
};
})
.get();
})
);
return {
title: title_dict[type],
link: `https://zbb.nju.edu.cn/${type}hw/index.chtml`,
item: [...items[0], ...items[1], ...items[2]],
};
}
}