diff --git a/docs/university.md b/docs/university.md index 7bf174cb3a..586b7eb67e 100644 --- a/docs/university.md +++ b/docs/university.md @@ -167,6 +167,40 @@ pageClass: routes +### 计算机科学与工程学院 + + + +| 学院新闻 | 学生科 | 教务科 | 研管科 | 学术看板 | +| ---------- | --------- | --------- | --------- | ---------- | +| xwzx\*xyxw | tzgg\*xsk | tzgg\*jwk | tzgg\*ygk | ztlj\*xskb | + +注 1: xwzx\*xyxw 对应 http://www.scse.uestc.edu.cn/xwzx/xyxw.htm ; +tzgg\*xsk 对应 http://www.scse.uestc.edu.cn/tzgg/xsk.htm + +可自定义设置 + +注 2; 用+号来叠加 学生科+教务科 `/uestc/cs/ztlj*xskb+tzgg*jwk` + + + +### 自动化工程学院 + + + +| 通知公告 | 学术看板 | 焦点新闻 | 综合新闻 | +| -------- | -------- | -------- | -------- | +| tzgg1 | xskb1 | jdxw | zhxw1 | + +注 1: tzgg1 对应 http://www.auto.uestc.edu.cn/index/tzgg1.htm ; +xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm + +可自定义设置 + +注 2: 用+号来叠加,通知公告+学术看板 `/uestc/auto/tzgg1+xskb1` + + + ## 东莞理工学院 ### 教务处通知 diff --git a/lib/router.js b/lib/router.js index 34ab02c444..b4b76790e4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -636,6 +636,8 @@ 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/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')); // 昆明理工大学 router.get('/kmust/jwc/:type?', require('./routes/universities/kmust/jwc')); diff --git a/lib/routes/universities/uestc/auto.js b/lib/routes/universities/uestc/auto.js new file mode 100644 index 0000000000..4332eb626b --- /dev/null +++ b/lib/routes/universities/uestc/auto.js @@ -0,0 +1,127 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +// 获取含有列表的页面 +async function loadTypePage(link) { + const Response = await got({ + method: 'get', + url: link, + }); + const data = Response.data; + return { data }; +} +// 同步获取含有列表的页面 +const ProcessListPage = async (list, caches) => + await Promise.all( + list.map(async (link) => { + const itemUrl = link; + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await loadTypePage(itemUrl)); + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, other)); + }) + ); + +// 完整文章页 +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + // 将style去掉 + const reg = /style\s*?=\s*?([‘"])[\s\S]*?\1/gi; + const description = $('div.v_news_content') + .html() + .replace(reg, ''); + + // addNoReferrer($, 'div#vsb_content', '', 'http://www.auto.uestc.edu.cn'); + // 提取内容 + return { description }; +} + +// 同步完整文章页 +const ProcessFeed = async (list, caches) => { + const host = 'http://www.auto.uestc.edu.cn/'; + + return await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('h6 a').text(); + + // 还原相对链接为绝对链接 + const itemUrl = $('h6 a') + .attr('href') + .replace('..', host); + const itemDate = new Date( + $('span') + .text() + .replace(/-/g, '/') + ).toUTCString(); + + // 列表上提取到的信息 + const single = { + title: title, + link: itemUrl, + author: '成电自动化', + guid: itemUrl, + pubDate: itemDate, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +}; + +// 通知公告 http://www.auto.uestc.edu.cn/index/tzgg1.htm +// 学术看板 http://www.auto.uestc.edu.cn/index/xskb1.htm +// 焦点新闻 http://www.auto.uestc.edu.cn/index/jdxw.htm +// 综合新闻 http://www.auto.uestc.edu.cn/index/zhxw1.htm + +// 测试:http://localhost:1200/uestc/auto/tzgg1+xskb1 +module.exports = async (ctx) => { + const baseUrl = 'http://www.auto.uestc.edu.cn/'; + const baseIndexUrl = 'http://www.auto.uestc.edu.cn/index/'; + + const type = ctx.params.type || 'tzgg1'; + const allType = type.split('+'); + + const listLink = []; + for (const idx in allType) { + listLink.push(baseIndexUrl + allType[idx] + '.htm'); + } + const Pages = await ProcessListPage(listLink, ctx.cache); + + // 合并要处理的link + let headName = '自动化'; + let list = null; + for (const idx in Pages) { + const $ = cheerio.load(Pages[idx].data); + headName = + headName + + '+' + + $('title') + .text() + .split('-')[0]; + if (list === null) { + list = $('dl.clearfix'); + } else { + list = $('dl.clearfix').append(list); + } + } + list = list.get(); + + // 处理所有的页面 + const result = await ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: headName, + link: baseUrl, + description: '电子科技大学 - ' + headName, + item: result, + }; +}; diff --git a/lib/routes/universities/uestc/cs.js b/lib/routes/universities/uestc/cs.js new file mode 100644 index 0000000000..c1bba37297 --- /dev/null +++ b/lib/routes/universities/uestc/cs.js @@ -0,0 +1,136 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +// const { addNoReferrer } = require('@/utils/common-utils'); + +// 获取含有列表的页面 +async function loadTypePage(link) { + const Response = await got({ + method: 'get', + url: link, + }); + const data = Response.data; + return { data }; +} +// 同步获取含有列表的页面 +const ProcessListPage = async (list, caches) => + await Promise.all( + list.map(async (link) => { + const itemUrl = link; + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await loadTypePage(itemUrl)); + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, other)); + }) + ); + +// 完整文章页 +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + // 将style去掉 + const reg = /style\s*?=\s*?([‘"])[\s\S]*?\1/gi; + const description = $('div#vsb_content') + .html() + .replace(reg, ''); + + // addNoReferrer($, 'div#vsb_content', '', 'http://www.scse.uestc.edu.cn'); + // 提取内容 + return { description }; +} + +const ProcessFeed = async (list, caches) => { + const host = 'http://www.scse.uestc.edu.cn/'; + + return await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('span a').text(); + // 还原相对链接为绝对链接 + const itemUrl = $('span a') + .attr('href') + .replace('..', host); + const itemDate = new Date( + $('span#time') + .text() + .replace(/-/g, '/') + ).toUTCString(); + + // 列表上提取到的信息 + const single = { + title: title, + link: itemUrl, + author: '成电计算机', + guid: itemUrl, + pubDate: itemDate, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +}; + +// 网站地图 http://www.scse.uestc.edu.cn/index/wzdt.htm +// 通知公告 +// 办公室 http://www.scse.uestc.edu.cn/tzgg/bgs.htm +// 组织人事 http://www.scse.uestc.edu.cn/tzgg/zzrs.htm +// 科研科 http://www.scse.uestc.edu.cn/tzgg/kyk.htm +// 研管科 http://www.scse.uestc.edu.cn/tzgg/ygk.htm +// 教务科 http://www.scse.uestc.edu.cn/tzgg/jwk.htm +// 学生科 http://www.scse.uestc.edu.cn/tzgg/xsk.htm +// 国际办 http://www.scse.uestc.edu.cn/tzgg/gjb.htm +// 综合教育 http://www.scse.uestc.edu.cn/tzgg/zhjy.htm +// 创新创业 http://www.scse.uestc.edu.cn/tzgg/cxcy.htm +// Info http://www.scse.uestc.edu.cn/tzgg/Info.htm +// 安全工作 http://www.scse.uestc.edu.cn/tzgg/aqgz.htm +// 学术看板 http://www.scse.uestc.edu.cn/ztlj/xskb.htm + +// 测试: http://localhost:1200/uestc/cs/ztlj*xskb+tzgg*jwk +module.exports = async (ctx) => { + const baseUrl = 'http://www.scse.uestc.edu.cn/'; + const type = ctx.params.type || 'ztlj*xskb'; + const allType = type.split('+'); + + const listLink = []; + for (const idx in allType) { + listLink.push(baseUrl + allType[idx].replace('*', '/') + '.htm'); + } + + const Pages = await ProcessListPage(listLink, ctx.cache); + + let headName = '计算机'; + let list = null; + // 合并要处理的link + for (const idx in Pages) { + const $ = cheerio.load(Pages[idx].data); + headName = + headName + + '+' + + $('title') + .text() + .split('-')[0]; + if (list === null) { + list = $('div#newsList').find('p'); + } else { + list = $('div#newsList') + .find('p') + .append(list); + } + } + list = list.get(); + + const result = await ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: headName, + link: baseUrl, + description: '电子科技大学 - ' + headName, + item: result, + }; +};