diff --git a/docs/university.md b/docs/university.md index 68b732306..851da5b35 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2159,6 +2159,48 @@ type 列表: +## 西安理工大学 + +### 学校主页 + + + +| 通知公告 | 校园要闻 | 媒体播报 | 学术活动 | +| :------: | :------: | :------: | :------: | +| tzgg | xyyw | mtbd | xshd | + + + +### 教务处 + + + +::: warning 注意 + +有些内容需使用校园网或 VPN 访问知行网获取 +::: + +| 通知公告 | 新闻动态 | 规章制度 | 竞赛结果公示 | 竞赛获奖通知 | 竞赛信息 | 公开公示 | +| :------: | :------: | :------: | :----------: | :----------: | :------: | :------: | +| tzgg | xwdt | gzzd | jggs | jsjg | jsxx | gkgs | + + + +### 人事处 + + + +::: warning 注意 + +有些内容指向外部链接,目前只提供这些链接,不提供具体内容,去除jwc和index的修改 +::: + +| 通知公告 | 工作动态 | +| :------: | :------: | +| tzgg | gzdt | + + + ## 西北工业大学 ### 翱翔门户 diff --git a/lib/v2/xaut/index.js b/lib/v2/xaut/index.js new file mode 100644 index 000000000..c7ca30f6f --- /dev/null +++ b/lib/v2/xaut/index.js @@ -0,0 +1,72 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let category = ctx.params.category; + const dic_html = { tzgg: 'tzgg.htm', xyyw: 'xyyw.htm', mtbd: 'mtbd1.htm', xshd: 'xshd.htm' }; + const dic_title = { tzgg: '通知公告', xyyw: '校园要闻', mtbd: '媒体播报', xshd: '学术活动' }; + + // 设置默认值 + if (dic_title[category] === undefined) { + category = 'tzgg'; + } + + const response = await got({ + method: 'get', + url: 'http://www.xaut.edu.cn/index/' + dic_html[category], + }); + const data = response.body; + const $ = cheerio.load(data); + + // 这个列表指通知公告详情列表 + const list = $('.newslist_block ul a') + .map((_, item) => { + item = $(item); + const temp = item.find('span').text(); + + // link原来长这样:'../info/1196/13990.htm' + const link = item.attr('href').replace(/^\.\./, 'http://www.xaut.edu.cn'); + let date = parseDate(temp.slice(-10, -1), 'YYYY-MM-DD'); + let title = temp.slice(0, -10); + + if (category === 'xshd') { + date = parseDate(temp.slice(-11, -1).replace('年', '-').replace('月', '-').replace('日', ''), 'YYYY-MM-DD'); + title = temp.slice(0, -11); + } + + return { + title, + link, + pubDate: date, + }; + }) + .get(); + + ctx.state.data = { + // 源标题 + title: '西安理工大学官网-' + dic_title[category], + // 源链接 + link: 'http://www.xaut.edu.cn', + // 源说明 + description: `西安理工大学官网-` + dic_title[category], + // 遍历此前获取的数据 + item: await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (!item.link.match('zhixing.xaut.edu.cn') && !item.link.match('xinwen.xaut.edu.cn')) { + const res = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(res.body); + item.description = content('#vsb_content').html(); + } else { + item.description = '请在校内或校园VPN内查看内容'; + } + return item; + }) + ) + ), + }; +}; diff --git a/lib/v2/xaut/jwc.js b/lib/v2/xaut/jwc.js new file mode 100644 index 000000000..59e473871 --- /dev/null +++ b/lib/v2/xaut/jwc.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let category = ctx.params.category; + const rootUrl = 'http://jwc.xaut.edu.cn/'; + const dic_html = { tzgg: 'tzgg.htm', xwdt: 'xwdt.htm', gzzd: 'gzzd.htm', jggs: 'xkjs/jggs.htm', jsjg: 'xkjs/jsjg.htm', jsxx: 'xkjs/jsxx.htm', gkgs: 'gkgs.htm' }; + const dic_title = { tzgg: '通知公告', xwdt: '新闻动态', gzzd: '规章制度', jggs: '竞赛结果公示', jsjg: '竞赛获奖通知', jsxx: '竞赛信息', gkgs: '公开公示' }; + + // 设置默认值 + if (dic_title[category] === undefined) { + category = 'tzgg'; + } + + const response = await got({ + method: 'get', + url: rootUrl + dic_html[category], + }); + const data = response.body; + const $ = cheerio.load(data); + + const list = $('.main_conRCb a') + .slice(0, 20) + .map((_, item) => { + item = $(item); + const link = item + .attr('href') + .replace(/^\.\./, rootUrl) + .replace(/^(info)/, rootUrl + 'info'); + return { + title: item.find('em').text(), + link, + pubDate: parseDate(item.find('span').text()), + }; + }) + .get(); + + ctx.state.data = { + // 源标题 + title: '西安理工大学教务处-' + dic_title[category], + // 源链接 + link: rootUrl, + // 源说明 + description: `西安理工大学教务处-` + dic_title[category], + // 遍历此前获取的数据 + item: await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (!item.link.match('zhixing.xaut.edu.cn') && !item.link.match('xinwen.xaut.edu.cn')) { + const res = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(res.body); + item.description = content('#vsb_content').html(); + } else { + item.description = '请在校内或校园VPN内查看内容'; + } + return item; + }) + ) + ), + }; +}; diff --git a/lib/v2/xaut/maintainer.js b/lib/v2/xaut/maintainer.js new file mode 100644 index 000000000..4f5e84e5f --- /dev/null +++ b/lib/v2/xaut/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/index/:category?': ['mocusez'], + '/jwc/:category?': ['mocusez'], + '/rsc/:category?': ['mocusez', 'light0926'], +}; diff --git a/lib/v2/xaut/radar.js b/lib/v2/xaut/radar.js new file mode 100644 index 000000000..d81ed9dbe --- /dev/null +++ b/lib/v2/xaut/radar.js @@ -0,0 +1,23 @@ +module.exports = { + 'xaut.edu.cn': { + _name: '西安理工大学', + index: [ + { + title: '学校官网', + docs: 'https://docs.rsshub.app/university.html#xi-an-li-gong-da-xue', + }, + ], + jwc: [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/university.html#xi-an-li-gong-da-xue', + }, + ], + rsc: [ + { + title: '人事处', + docs: 'https://docs.rsshub.app/university.html#xi-an-li-gong-da-xue', + }, + ], + }, +}; diff --git a/lib/v2/xaut/router.js b/lib/v2/xaut/router.js new file mode 100644 index 000000000..f4d28cdb9 --- /dev/null +++ b/lib/v2/xaut/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/index/:category?', require('./index')); + router.get('/jwc/:category?', require('./jwc')); + router.get('/rsc/:category?', require('./rsc')); +}; diff --git a/lib/v2/xaut/rsc.js b/lib/v2/xaut/rsc.js new file mode 100644 index 000000000..9adfc3488 --- /dev/null +++ b/lib/v2/xaut/rsc.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let category = ctx.params.category; + // 这里的category是个形参 + const dic_html = { tzgg: 'tzgg.htm', gzdt: 'gzdt.htm' }; + const dic_title = { tzgg: '通知公告', gzdt: '工作动态' }; + + // 设置默认值 + if (dic_title[category] === undefined) { + category = 'tzgg'; + } + + const response = await got({ + method: 'get', + url: 'http://renshichu.xaut.edu.cn/' + dic_html[category], + }); + const data = response.body; + const $ = cheerio.load(data); + + // 这个列表指通知公告详情列表 + const list = $('.vsb-space.n_right .list .cleafix') + .map((_, item) => { + item = $(item); + // 工作动态栏目里有一些是外链,这里做个判断 + const a = item.find('.list_wen a').eq(0).attr('href'); + const link = a.slice(0, 4) !== 'http' ? 'http://renshichu.xaut.edu.cn/' + a : a; + // 这里jquery比较长,引几个中间变量倒是方便阅读,但是我还是觉得不需要 + const title = item.find('.list_wen a.tit').text(); + return { + title, + link, + }; + }) + .get(); + ctx.state.data = { + // 源标题 + title: '西安理工大学人事处-' + dic_title[category], + // 源链接 + link: 'http://renshichu.xaut.edu.cn', + // 源说明 + description: `西安理工大学人事处-` + dic_title[category], + // 遍历此前获取的数据 + item: await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + // 下面的if判断是否属于外链,使用切片的方式来判断,并不优雅,先用着吧 + if (item.link.slice(0, 16) === 'http://renshichu') { + // 不属于外链 + const res = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(res.body); + item.description = content('.vsb-space form[name]').html(); + item.pubDate = parseDate(content('.vsb-space form[name] h3 span:contains(时间)').text().slice(3)); + } else { + item.description = '这是一个外链("▔□▔)/("▔□▔)/所以你没法直接看到内容' + item.link; + } + return item; + }) + ) + ), + }; +};