feat: 浙江大学软件学院 RSS 添加通知内容 (#4808)
This commit is contained in:
parent
f02e01c004
commit
148e017f31
|
|
@ -1574,9 +1574,9 @@ type 列表:
|
|||
|
||||
<Route author="yonvenne zwithz" example="/zju/cst/0" path="/zju/cst/:type" :paramsDesc="['分类, 见下表']" radar="1">
|
||||
|
||||
| 全部通知 | 招生信息 | 教务管理 | 论文管理 | 思政工作 | 评奖评优 | 实习就业 | 国内合作科研 | 国际合作科研 | |
|
||||
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | ------------ | ------------ | - |
|
||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
||||
| 全部通知 | 招生信息 | 教务管理 | 论文管理 | 思政工作 | 评奖评优 | 实习就业 | 国际实习 | 国内合作科研 | 国际合作科研 |
|
||||
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ------------ | ------------ |
|
||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
||||
|
||||
</Route>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,22 @@ const cheerio = require('cheerio');
|
|||
const host = 'http://www.cst.zju.edu.cn/';
|
||||
|
||||
const map = new Map([
|
||||
[1, { id: '32178', title: '浙大软件学院-招生信息' }],
|
||||
[2, { id: '36216', title: '浙大软件学院-教务管理' }],
|
||||
[3, { id: '36217', title: '浙大软件学院-论文管理' }],
|
||||
[4, { id: '36224', title: '浙大软件学院-思政工作' }],
|
||||
[5, { id: '36228', title: '浙大软件学院-评奖评优' }],
|
||||
[6, { id: '36233', title: '浙大软件学院-实习就业' }],
|
||||
[7, { id: '36235', title: '浙大软件学院-国际实习' }],
|
||||
[8, { id: '36194', title: '浙大软件学院-国内合作科研' }],
|
||||
[9, { id: '36246', title: '浙大软件学院-国际合作科研' }],
|
||||
[0, { id: '', title: '浙大软件学院-全部通知' }],
|
||||
[1, { id: '32178/list.htm', title: '浙大软件学院-招生信息' }],
|
||||
[2, { id: '36216/list.htm', title: '浙大软件学院-教务管理' }],
|
||||
[3, { id: '36217/list.htm', title: '浙大软件学院-论文管理' }],
|
||||
[4, { id: '36224/list.htm', title: '浙大软件学院-思政工作' }],
|
||||
[5, { id: '36228/list.htm', title: '浙大软件学院-评奖评优' }],
|
||||
[6, { id: '36233/list.htm', title: '浙大软件学院-实习就业' }],
|
||||
[7, { id: '36235/list.htm', title: '浙大软件学院-国际实习' }],
|
||||
[8, { id: '36194/list.htm', title: '浙大软件学院-国内合作科研' }],
|
||||
[9, { id: '36246/list.htm', title: '浙大软件学院-国际合作科研' }],
|
||||
]);
|
||||
|
||||
async function getPage(id) {
|
||||
const res = await got({
|
||||
method: 'get',
|
||||
url: host + `${id}` + '/list.htm',
|
||||
url: host + id,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(res.data);
|
||||
|
|
@ -32,7 +33,7 @@ async function getPage(id) {
|
|||
return {
|
||||
title: item.find('a').text(),
|
||||
pubDate: new Date(item.find('.fr').text()).toUTCString(),
|
||||
link: `http://www.cst.zju.edu.cn/${item.find('a').attr('href')}`,
|
||||
link: item.find('a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get()
|
||||
|
|
@ -41,27 +42,52 @@ async function getPage(id) {
|
|||
|
||||
module.exports = async (ctx) => {
|
||||
const type = Number.parseInt(ctx.params.type);
|
||||
const link = host + map.get(type).id;
|
||||
let items = [];
|
||||
if (type === 0) {
|
||||
const tasks = [];
|
||||
for (const value of map.values()) {
|
||||
tasks.push(getPage(value.id));
|
||||
}
|
||||
const results = await Promise.all(tasks);
|
||||
let items = [];
|
||||
results.forEach((result) => {
|
||||
items = items.concat(result);
|
||||
});
|
||||
ctx.state.data = {
|
||||
title: '浙大软件学院-全部通知',
|
||||
link: host,
|
||||
item: items,
|
||||
};
|
||||
} else {
|
||||
const id = map.get(type).id;
|
||||
ctx.state.data = {
|
||||
title: map.get(type).title,
|
||||
link: host + `${id}` + '/list.htm',
|
||||
item: await getPage(id),
|
||||
};
|
||||
items = await getPage(map.get(type).id);
|
||||
}
|
||||
|
||||
const out = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
const itemUrl = host + item.link;
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: itemUrl,
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const description = $('.vid_wz').html();
|
||||
const single = {
|
||||
title: item.title,
|
||||
link: itemUrl,
|
||||
description: description,
|
||||
pubDate: item.pubDate,
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: map.get(type).title,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue