reorganize sjtu-seiee section (#1981)

This commit is contained in:
Jiamin Shen
2019-04-25 12:05:53 +08:00
committed by DIYgod
parent 23bda4d24b
commit 53c25b3084
11 changed files with 182 additions and 436 deletions

View File

@@ -139,15 +139,13 @@
<Route name="电子信息与电气工程学院学术动态" author="HenryQW" example="/sjtu/seiee/academic" path="/universities/sjtu/seiee/academic"/> <Route name="电子信息与电气工程学院学术动态" author="HenryQW" example="/sjtu/seiee/academic" path="/universities/sjtu/seiee/academic"/>
<Route name="电子信息与电气工程学院本科教务办 -- 分专业" author="SkyZH" example="/sjtu/seiee/bjwb/major_select" path="/universities/sjtu/seiee/bjwb/major_select"/> <Route name="电子信息与电气工程学院本科教务办" author="Polynomia" example="/sjtu/seiee/xsb/news" path="/universities/sjtu/seiee/bjwb/:type" :paramsDesc="['无默认选项']">
<Route name="电子信息与电气工程学院本科教务办 -- 转专业" author="SkyZH" example="/sjtu/seiee/bjwb/major_transfer" path="/universities/sjtu/seiee/bjwb/major_transfer"/> | 分专业 | 转专业 | 直升研究生 | 交换交流 | 国际办学 |
| ------------ | -------------- | ------------ | -------- | ------------- |
| major_select | major_transfer | postgraduate | abroad | international |
<Route name="电子信息与电气工程学院本科教务办 -- 交换交流" author="SkyZH" example="/sjtu/seiee/bjwb/abroad" path="/universities/sjtu/seiee/bjwb/abroad"/> </Route>
<Route name="电子信息与电气工程学院本科教务办 -- 直升研究生" author="SkyZH" example="/sjtu/seiee/bjwb/postgraduate" path="/universities/sjtu/seiee/bjwb/postgraduate"/>
<Route name="电子信息与电气工程学院本科教务办 -- 国际办学" author="SkyZH" example="/sjtu/seiee/bjwb/international" path="/universities/sjtu/seiee/bjwb/international"/>
<Route name="研究生通知公告" author="mzr1996" example="/sjtu/gs/tzgg/pyxx" path="/universities/sjtu/gs/tzgg/:type?" :paramsDesc="['默认列举所有通知公告']"> <Route name="研究生通知公告" author="mzr1996" example="/sjtu/gs/tzgg/pyxx" path="/universities/sjtu/gs/tzgg/:type?" :paramsDesc="['默认列举所有通知公告']">

View File

@@ -607,11 +607,7 @@ router.get('/shanghaitech/sist/activity', require('./routes/universities/shangha
// 上海交通大学 // 上海交通大学
router.get('/sjtu/seiee/academic', require('./routes/universities/sjtu/seiee/academic')); router.get('/sjtu/seiee/academic', require('./routes/universities/sjtu/seiee/academic'));
router.get('/sjtu/seiee/bjwb/major_select', require('./routes/universities/sjtu/seiee/bjwb/major_select')); router.get('/sjtu/seiee/bjwb/:type', require('./routes/universities/sjtu/seiee/bjwb'));
router.get('/sjtu/seiee/bjwb/major_transfer', require('./routes/universities/sjtu/seiee/bjwb/major_transfer'));
router.get('/sjtu/seiee/bjwb/postgraduate', require('./routes/universities/sjtu/seiee/bjwb/postgraduate'));
router.get('/sjtu/seiee/bjwb/abroad', require('./routes/universities/sjtu/seiee/bjwb/abroad'));
router.get('/sjtu/seiee/bjwb/international', require('./routes/universities/sjtu/seiee/bjwb/international'));
router.get('/sjtu/seiee/xsb/:type?', require('./routes/universities/sjtu/seiee/xsb')); router.get('/sjtu/seiee/xsb/:type?', require('./routes/universities/sjtu/seiee/xsb'));
router.get('/sjtu/gs/tzgg/:type?', require('./routes/universities/sjtu/gs/tzgg')); router.get('/sjtu/gs/tzgg/:type?', require('./routes/universities/sjtu/gs/tzgg'));

View File

@@ -1,52 +1,26 @@
const axios = require('../../../../utils/axios'); const workerFactory = require('./utils');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.seiee.sjtu.edu.cn/'; module.exports = workerFactory(
() => ({
module.exports = async (ctx) => { title: '上海交通大学电子信息与电气工程学院本科教务办 -- 学术动态',
const link = url.resolve(host, 'seiee/list/683-1-20.htm'); local: `seiee/list/683-1-20.htm`,
const response = await axios.get(link); author: '上海交通大学电子信息与电气工程学院本科教务办',
}),
const $ = cheerio.load(response.data); ($) =>
$('.list_box_5 li')
const list = $('.list_style_1 li a')
.slice(0, 10) .slice(0, 10)
.map((i, e) => $(e).attr('href')) .map((i, e) => ({
.get(); date: $(e)
.children('span')
const out = await Promise.all(
list.map(async (itemUrl) => {
itemUrl = url.resolve(host, itemUrl);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: $('h2.title_3').text(),
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院',
description: $('.c_1.article_content')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`),
pubDate: new Date(
$('.date_1 span:first-of-type')
.text() .text()
.trim() .slice(1, -1),
).toUTCString(), title: $(e)
}; .children('a')
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); .text()
return Promise.resolve(single); .slice(2),
}) link: $(e)
); .children('a')
.attr('href'),
ctx.state.data = { }))
title: '上海交通大学电子信息与电气工程学院 -- 学术动态', .get()
link, );
item: out,
};
};

View File

@@ -0,0 +1,53 @@
const workerFactory = require('./utils');
module.exports = workerFactory(
(ctx) => {
const config = {
abroad: {
link: `bkjwb/list/1507-1-20.htm`,
title: '交换交流',
},
international: {
link: `bkjwb/list/2281-1-20.htm`,
title: '国际办学通知',
},
major_select: {
link: `bkjwb/list/1503-1-20.htm`,
title: '分专业',
},
major_transfer: {
link: `bkjwb/list/1505-1-20.htm`,
title: '转专业',
},
postgraduate: {
link: `bkjwb/list/1506-1-20.htm`,
title: '直升研究生',
},
};
const type = ctx.params.type;
return {
title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title,
local: config[type].link,
author: '上海交通大学电子信息与电气工程学院本科教务办',
};
},
($) =>
$('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get()
);

View File

@@ -1,58 +0,0 @@
const axios = require('../../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = async (ctx) => {
const link = url.resolve(host, `bkjwb/list/1507-1-20.htm`);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院本科教务办',
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院本科教务办 -- 交换交流',
link,
item: out,
};
};

View File

@@ -1,58 +0,0 @@
const axios = require('../../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = async (ctx) => {
const link = url.resolve(host, `bkjwb/list/2281-1-20.htm`);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院本科教务办',
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院本科教务办 -- 国际办学通知',
link,
item: out,
};
};

View File

@@ -1,58 +0,0 @@
const axios = require('../../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = async (ctx) => {
const link = url.resolve(host, 'bkjwb/list/1503-1-20.htm');
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院本科教务办',
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院本科教务办 -- 分专业',
link,
item: out,
};
};

View File

@@ -1,58 +0,0 @@
const axios = require('../../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = async (ctx) => {
const link = url.resolve(host, 'bkjwb/list/1505-1-20.htm');
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院本科教务办',
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院本科教务办 -- 转专业',
link,
item: out,
};
};

View File

@@ -1,58 +0,0 @@
const axios = require('../../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = async (ctx) => {
const link = url.resolve(host, 'bkjwb/list/1506-1-20.htm');
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('.list_box_5 li')
.slice(0, 10)
.map((i, e) => ({
date: $(e)
.children('span')
.text()
.slice(1, -1),
title: $(e)
.children('a')
.text()
.slice(2),
link: $(e)
.children('a')
.attr('href'),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院本科教务办',
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院本科教务办 -- 直升研究生',
link,
item: out,
};
};

View File

@@ -0,0 +1,45 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://bjwb.seiee.sjtu.edu.cn';
module.exports = function(meta, extract) {
return async (ctx) => {
const { title, local, author } = meta(ctx);
const link = url.resolve(host, local);
const response = await axios.get(link);
const list = extract(cheerio.load(response.data));
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author,
description: $('.article_content').text(),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title,
link,
item: out,
};
};
};

View File

@@ -1,44 +1,44 @@
const axios = require('../../../../utils/axios'); const workerFactory = require('./utils');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://xsb.seiee.sjtu.edu.cn'; module.exports = workerFactory(
const config = { (ctx) => {
const config = {
news: { news: {
link: `xsb/list/2938-1-20.htm`, link: 'xsb/list/2938-1-20.htm',
title: '新闻发布', title: '新闻发布',
}, },
scholarship: { scholarship: {
link: `xsb/list/611-1-20.htm`, link: 'xsb/list/611-1-20.htm',
title: '奖学金', title: '奖学金',
}, },
activity: { activity: {
link: `xsb/list/2676-1-20.htm`, link: 'xsb/list/2676-1-20.htm',
title: '党团活动', title: '党团活动',
}, },
lecture: { lecture: {
link: `xsb/list/1981-1-20.htm`, link: 'xsb/list/1981-1-20.htm',
title: '讲座活动', title: '讲座活动',
}, },
all: { all: {
link: `xsb/list/705-1-20.htm`, link: 'xsb/list/705-1-20.htm',
title: '信息通告', title: '信息通告',
}, },
financialAid: { financialAid: {
link: `xsb/list/1001-1-20.htm`, link: 'xsb/list/1001-1-20.htm',
title: '助学金', title: '助学金',
}, },
}; };
module.exports = async (ctx) => { const type = ctx.params.type || 'all';
let type = ctx.params.type;
type = type ? type : 'all';
const link = url.resolve(host, config[type].link);
const response = await axios.get(link);
const $ = cheerio.load(response.data); return {
title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title,
const list = $('.list_box_5_2 li') local: config[type].link,
author: '上海交通大学电子信息与电气工程学院学生工作办公室',
};
},
($) =>
$('.list_box_5_2 li')
.slice(0, 10) .slice(0, 10)
.map((i, e) => ({ .map((i, e) => ({
date: $(e) date: $(e)
@@ -53,35 +53,5 @@ module.exports = async (ctx) => {
.children('a') .children('a')
.attr('href'), .attr('href'),
})) }))
.get(); .get()
);
const out = await Promise.all(
list.map(async (item) => {
const itemUrl = url.resolve(host, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: item.title,
link: itemUrl,
author: '上海交通大学电子信息与电气工程学院学生工作办公室',
description: $('.article_box')
.text()
.slice(0, -7),
pubDate: new Date(item.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title,
link,
item: out,
};
};