diff --git a/docs/university.md b/docs/university.md index 0d750ddbc..521336f34 100644 --- a/docs/university.md +++ b/docs/university.md @@ -354,6 +354,38 @@ pageClass: routes +## 大连理工大学 + +### 教务处 + + + +| 重要通告 | 新闻快递 | 教学文件 | 其他文件 | +| -------- | -------- | -------------- | ----------- | +| zytg | xwkd | jiaoxuewenjian | qitawenjian | + + + +### 体育场馆中心 + + + +| 通知公告 | 活动日程 | 新闻动态 | +| -------- | -------- | -------- | +| tzgg | hdrc | xwdt | + + + +### 国际处及港澳台办 + + + +| 学生通知 | 教师通知 | 新闻速递 | +| ---------- | -------- | -------- | +| xstong_zhi | jstz | xwsd | + + + ## 电子科技大学 ### 教务处 diff --git a/lib/router.js b/lib/router.js index 81c757eac..f24a22fa5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/universities/dut/index.js b/lib/routes/universities/dut/index.js new file mode 100644 index 000000000..59071ce99 --- /dev/null +++ b/lib/routes/universities/dut/index.js @@ -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, + }; +}; diff --git a/lib/routes/universities/dut/subsite.js b/lib/routes/universities/dut/subsite.js new file mode 100644 index 000000000..c289ea05e --- /dev/null +++ b/lib/routes/universities/dut/subsite.js @@ -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(/
  • /g, '
  • ').replace(/<\/li>/g, '

  • '); + attachment = (attachment ? attachment : '').replace(/
  • /g, '
  • '); + return main + '
    ' + 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;