diff --git a/docs/university.md b/docs/university.md index 4e2d6b607..7cd6a7a73 100644 --- a/docs/university.md +++ b/docs/university.md @@ -416,6 +416,16 @@ xskb1 对应 +### 信息与软件工程学院 + + + +| 最新 | 院办 | 组织 | 学生科 | 教务科 | 研管科 | 实验中心 | 企业技术服务中心 | 新工科中心 | 实习实训办公室 | 招聘 | 实习实训 | +| --- | ---- | --- | ----- | ----- | ---- | ------- | ------------- | -------- | --------- | --- | ------ | +| latest | yb | zx | xsk | jwk | ygk | syzx | qyjsfwzx | xgkzx | sxsxbgs | zp | sxsx | + +注: 可以使用 + 号来叠加,如 学生科 + 教务科 `/uestc/is/xsk+jwc` + ## 东北大学 ### 东北大学新闻网 diff --git a/lib/router.js b/lib/router.js index 69a373e9a..f98d88997 100644 --- a/lib/router.js +++ b/lib/router.js @@ -786,6 +786,7 @@ router.get('/sctu/jwc/:type/:id', require('./routes/universities/sctu/jwc/contex // 电子科技大学 router.get('/uestc/jwc/:type?', require('./routes/universities/uestc/jwc')); +router.get('/uestc/is/:type?', require('./routes/universities/uestc/is')); router.get('/uestc/news/:type?', require('./routes/universities/uestc/news')); router.get('/uestc/auto/:type?', require('./routes/universities/uestc/auto')); router.get('/uestc/cs/:type?', require('./routes/universities/uestc/cs')); diff --git a/lib/routes/universities/uestc/is.js b/lib/routes/universities/uestc/is.js new file mode 100644 index 000000000..1a30f44be --- /dev/null +++ b/lib/routes/universities/uestc/is.js @@ -0,0 +1,104 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +// 首页 https://www.is.uestc.edu.cn/ +// 通知公告 +// 最新公告无单独页面 +// 院办 https://www.is.uestc.edu.cn/noticesList.do?type=91 +// 组织 https://www.is.uestc.edu.cn/noticesList.do?type=132 +// 学生科 https://www.is.uestc.edu.cn/noticesList.do?type=90 +// 教务科 https://www.is.uestc.edu.cn/noticesList.do?type=93 +// 研管科 https://www.is.uestc.edu.cn/noticesList.do?type=92 +// 实验中心 https://www.is.uestc.edu.cn/noticesList.do?type=97 +// 企业技术服务中心 https://www.is.uestc.edu.cn/noticesList.do?type=185 +// 新工科中心 https://www.is.uestc.edu.cn/noticesList.do?type=184 +// 实习实训办公室 https://www.is.uestc.edu.cn/noticesList.do?type=96 +// 招聘 https://www.is.uestc.edu.cn/noticesList.do?type=137 +// 实习实训 https://www.is.uestc.edu.cn/noticesList.do?type=135 + +const baseUrl = 'https://www.is.uestc.edu.cn/'; +const listUrl = baseUrl + 'noticesList.do?type='; + +const types = { + latest: 'latest', + yb: 91, + zx: 132, + xsk: 90, + jwk: 93, + ygk: 92, + syzx: 97, + qyjsfwzx: 185, + xgkzx: 184, + sxsxbgs: 96, + zp: 135, + sxsx: 137, +}; + +const convertDate = (text) => { + const date = new Date(text); + const now = new Date(); + if (now.getMonth() > date.getMonth()) { + return new Date(`${new Date().getFullYear()}-${text}`); + } else { + if (now.getMonth() < date.getMonth() && now.getMonth() === date.getMonth() && now.getDate() < date.getDate()) { + return new Date(`${new Date().getFullYear() - 1}-${text}`); + } + } +}; + +const getTypeItems = async (type) => { + if (type !== 'latest') { + const res = await got({ + method: 'get', + url: listUrl + types[type], + headers: { + Referer: baseUrl, + }, + }); + + const $ = cheerio.load(res.data); + + return $('.new-list li a') + .slice(0, 10) + .map((_, elem) => ({ + link: baseUrl + elem.attribs.href, + title: elem.attribs.title, + pubDate: new Date($(elem).children('.new-time').text()).toUTCString(), + })) + .get(); + } else { + const res = await got({ + method: 'get', + url: baseUrl, + headers: { + Referer: baseUrl, + }, + }); + + const $ = cheerio.load(res.data); + + return $('.annce-cont ul li div') + .slice(0, 10) + .map((_, elem) => ({ + link: baseUrl + $(elem).children('a').attr('href'), + title: $(elem).children('a').attr('title'), + pubDate: convertDate($(elem).children('span').text()), + })) + .get(); + } +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'latest'; + const allTypes = type.split('+'); + + const result = await Promise.all( + allTypes.map((t) => getTypeItems(t)), + ); + + ctx.state.data = { + title: '电子科技大学信软学院通知公告', + link: baseUrl, + item: result.flat(), + }; +};