feat(route): add route universities/dut (#7765)

This commit is contained in:
BeautyYuYanli 2021-06-27 08:10:39 +08:00 committed by GitHub
parent 87980a9e5b
commit 3e5c8f2e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 145 additions and 0 deletions

View File

@ -354,6 +354,38 @@ pageClass: routes
</Route>
## 大连理工大学
### 教务处
<Route author="beautyyuyanli" example="/dut/teach/zytg" path="/dut/teach/:type" :paramsDesc="['通知类型']">
| 重要通告 | 新闻快递 | 教学文件 | 其他文件 |
| -------- | -------- | -------------- | ----------- |
| zytg | xwkd | jiaoxuewenjian | qitawenjian |
</Route>
### 体育场馆中心
<Route author="beautyyuyanli" example="/dut/tycgzx/hdrc" path="/dut/tycgzx/:type" :paramsDesc="['通知类型']">
| 通知公告 | 活动日程 | 新闻动态 |
| -------- | -------- | -------- |
| tzgg | hdrc | xwdt |
</Route>
### 国际处及港澳台办
<Route author="beautyyuyanli" example="/dut/dutdice/xwsd" path="/dut/dutdice/:type" :paramsDesc="['通知类型']">
| 学生通知 | 教师通知 | 新闻速递 |
| ---------- | -------- | -------- |
| xstong_zhi | jstz | xwsd |
</Route>
## 电子科技大学
### 教务处

View File

@ -627,6 +627,9 @@ router.get('/bjtu/gs/:type', require('./routes/universities/bjtu/gs'));
router.get('/dpu/jiaowu/news/:type?', require('./routes/universities/dpu/jiaowu/news'));
router.get('/dpu/wlfw/news/:type?', require('./routes/universities/dpu/wlfw/news'));
// 大连理工大学
router.get('/dut/:subsite/:type', require('./routes/universities/dut/index'));
// 东南大学
router.get('/seu/radio/academic', require('./routes/universities/seu/radio/academic'));
router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb'));

View File

@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const subsiteDic = require('./subsite.js');
module.exports = async (ctx) => {
const subsiteMap = subsiteDic[ctx.params.subsite];
const typeMap = subsiteMap.typeMap[ctx.params.type];
const frontUrl = typeMap.url;
const basePath = typeMap.basePath;
const response = await got({
method: 'get',
url: frontUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $(subsiteMap.listSelector)
.map((index, item) => {
item = $(item);
return {
title: subsiteMap.titleMethod(item),
// description: description,
link: subsiteMap.linkMethod(item),
pubDate: timezone(parseDate(subsiteMap.pubDateMethod(item), 'YYYY/MM/DD'), +8),
};
})
.get();
const entries = await Promise.all(
list.map(async (item) => {
const { title, link, pubDate } = item;
const entryUrl = basePath + link;
const cache = await ctx.cache.tryGet(entryUrl, async () => {
const response = await got({
method: 'get',
url: entryUrl,
});
const $ = cheerio.load(response.data);
const description = subsiteMap.descriptionMethod($);
const entry = {
title: title,
link: link,
pubDate: pubDate,
description: description,
};
return JSON.stringify(entry);
});
return Promise.resolve(JSON.parse(cache));
})
);
ctx.state.data = {
title: typeMap.title,
link: frontUrl,
item: entries,
};
};

View File

@ -0,0 +1,50 @@
const titleMethod1 = (item) => item.find('a').text();
const linkMethod1 = (item) => item.find('a').attr().href;
const pubDateMethod1 = (item) => item.find('span').text();
const descriptionMethod1 = ($) => {
const main = $('.v_news_content').html();
let attachment = $('form ul').html();
// attachment = (attachment ? attachment : '').replace(/<li>/g, '<li><p>').replace(/<\/li>/g, '</p></li>');
attachment = (attachment ? attachment : '').replace(/<li>/g, '<br><li>');
return main + '<br>' + attachment;
};
const subsiteDic = {
teach: {
listSelector: '.list > ul > li',
titleMethod: titleMethod1,
linkMethod: linkMethod1,
pubDateMethod: pubDateMethod1,
descriptionMethod: descriptionMethod1,
typeMap: {
zytg: { title: '大连理工大学教务处-重要通告', url: 'https://teach.dlut.edu.cn/zytg/zytg.htm', basePath: 'https://teach.dlut.edu.cn/zytg/' },
xwkd: { title: '大连理工大学教务处-新闻快递', url: 'https://teach.dlut.edu.cn/xwkd/xwkd.htm', basePath: 'https://teach.dlut.edu.cn/xwkd/' },
qitawenjian: { title: '大连理工大学教务处-其他文件', url: 'https://teach.dlut.edu.cn/qitawenjian/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1081', basePath: 'https://teach.dlut.edu.cn/qitawenjian/' },
jiaoxuewenjian: { title: '大连理工大学教务处-教学文件', url: 'https://teach.dlut.edu.cn/jiaoxuewenjian/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1082', basePath: 'https://teach.dlut.edu.cn/jiaoxuewenjian/' },
},
},
dutdice: {
listSelector: '.list01 li',
titleMethod: titleMethod1,
linkMethod: linkMethod1,
pubDateMethod: pubDateMethod1,
descriptionMethod: descriptionMethod1,
typeMap: {
xstong_zhi: { title: '大连理工大学国际处及港澳台办-学生通知', url: 'http://dutdice.dlut.edu.cn/tzgg/xstong_zhi.htm', basePath: 'http://dutdice.dlut.edu.cn/tzgg/' },
jstz: { title: '大连理工大学国际处及港澳台办-教师通知', url: 'http://dutdice.dlut.edu.cn/tzgg/jstz.htm', basePath: 'http://dutdice.dlut.edu.cn/tzgg/' },
xwsd: { title: '大连理工大学国际处及港澳台办-新闻速递', url: 'http://dutdice.dlut.edu.cn/xwsd/xxxw.htm', basePath: 'http://dutdice.dlut.edu.cn/xwsd/' },
},
},
tycgzx: {
listSelector: '.list li',
titleMethod: titleMethod1,
linkMethod: linkMethod1,
pubDateMethod: pubDateMethod1,
descriptionMethod: descriptionMethod1,
typeMap: {
tzgg: { title: '大连理工大学体育场馆中心-通知公告', url: 'http://tycgzx.dlut.edu.cn/tzgg/tzgg.htm', basePath: 'http://tycgzx.dlut.edu.cn/tzgg/' },
hdrc: { title: '大连理工大学体育场馆中心-活动日程', url: 'http://tycgzx.dlut.edu.cn/hdrc/hdrc.htm', basePath: 'http://tycgzx.dlut.edu.cn/hdrc/' },
xwdt: { title: '大连理工大学体育场馆中心-新闻动态', url: 'http://tycgzx.dlut.edu.cn/xwdt/xwdt.htm', basePath: 'http://tycgzx.dlut.edu.cn/xwdt/' },
},
},
};
module.exports = subsiteDic;