Skip to content

Commit

Permalink
feat: 浙江大学软件学院 RSS 添加通知内容 (DIYgod#4808)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwithz authored May 24, 2020
1 parent f02e01c commit 148e017
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
6 changes: 3 additions & 3 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
72 changes: 49 additions & 23 deletions lib/routes/universities/zju/cst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand All @@ -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,
};
};

0 comments on commit 148e017

Please sign in to comment.