From d97fade9970dc207454147aa2ff3035758417251 Mon Sep 17 00:00:00 2001 From: Veagau Gendhi <28336196+Veagau@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:32:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E7=9F=B3=E6=B2=B9=E5=A4=A7=E5=AD=A6=EF=BC=88=E5=8D=8E=E4=B8=9C?= =?UTF-8?q?=EF=BC=89=E7=9A=84=E8=B7=AF=E7=94=B1=20(#3336)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 34 ++++++++++-- lib/router.js | 4 ++ lib/routes/universities/upc/jsj.js | 81 +++++++++++++++++++++++++++++ lib/routes/universities/upc/main.js | 72 +++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 lib/routes/universities/upc/jsj.js create mode 100644 lib/routes/universities/upc/main.js diff --git a/docs/university.md b/docs/university.md index 661783b730..62af5eb440 100644 --- a/docs/university.md +++ b/docs/university.md @@ -267,12 +267,14 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm ### 东南大学计算机技术与工程学院 - + | 学院新闻 | 通知公告 | 教务信息 | 就业信息 | 学工事务 | | -------- | -------- | -------- | -------- | -------- | | xyxw | tzgg | jwxx | jyxx | xgsw | + + ## 广东工业大学 ### 校内新闻网 @@ -540,20 +542,24 @@ category 列表: ### 计算机科学与技术学院 - + | 通知公告 | 新闻动态 | 科研动态 | 教学动态 | 学生工作 | 招生信息 | 就业信息 | | -------- | -------- | -------- | -------- | -------- | -------- | -------- | | tzgg | xwdt | kydt | jxdt | xsgz | zsxx | jyxx | + + ### 研究生院 - + | 最近动态 | 研院新闻 | 上级文件 | 管理文件 | 信息服务 | | -------- | -------- | -------- | -------- | -------- | | latest | yyxw | sjwj | glwj | xxfw | + + ## 南京理工大学 ### 南京理工大学教务处 @@ -1116,3 +1122,25 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet ### 数据科学与计算机学院动态 + +## 中国石油大学(华东) + +### 主页 + + + +| 通知公告 | 学术动态 | +| -------- | -------- | +| notice | scholar | + + + +### 计算机科学与技术学院 + + + +| 学院新闻 | 学术关注 | 学工动态 | 通知公告 | +| -------- | -------- | -------- | -------- | +| news | scholar | states | notice | + + diff --git a/lib/router.js b/lib/router.js index a2166e0709..fc9ae2bd9f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -705,6 +705,10 @@ router.get('/ustb/tj/news/:type?', require('./routes/universities/ustb/tj/news') // 深圳大学 router.get('/szu/yz/:type?', require('./routes/universities/szu/yz')); +// 中国石油大学(华东) +router.get('/upc/main/:type?', require('./routes/universities/upc/main')); +router.get('/upc/jsj/:type?', require('./routes/universities/upc/jsj')); + // ifanr router.get('/ifanr/:channel?', require('./routes/ifanr/index')); diff --git a/lib/routes/universities/upc/jsj.js b/lib/routes/universities/upc/jsj.js new file mode 100644 index 0000000000..92ad4fd4b4 --- /dev/null +++ b/lib/routes/universities/upc/jsj.js @@ -0,0 +1,81 @@ +// 计算机科学与技术学院:http://computer.upc.edu.cn/ +// - 学院新闻:http://computer.upc.edu.cn/6277/list.htm +// - 学术关注:http://computer.upc.edu.cn/6278/list.htm +// - 学工动态:http://computer.upc.edu.cn/6279/list.htm +// - 通知公告:http://computer.upc.edu.cn/6280/list.htm + +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const baseurl = 'http://computer.upc.edu.cn/'; +// 地址映射 +const MAP = { + news: '6277', + scholar: '6278', + states: '6279', + notice: '6280', +}; +// 头部信息 +const HEAD = { + news: '学院新闻', + scholar: '学术关注', + states: '学工动态', + notice: '通知公告', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type; + const response = await got({ + method: 'get', + url: baseurl + MAP[type] + '/list.htm', + }); + const $ = cheerio.load(response.data); + // ## 获取列表 + const list = $('#wp_news_w15 > table > tbody > tr > td > table > tbody > tr > td > a').get(); + // ## 定义输出的item + const out = await Promise.all( + // ### 遍历列表,筛选出自己想要的内容 + list.map(async (item) => { + const itemSingle = cheerio.load(item); + const title = itemSingle.text(); + const re = /]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g; + let singleUrl = ''; + if (re.exec(itemSingle.html()) !== null) { + singleUrl = RegExp.$1; + } + if (singleUrl.search('http') === -1) { + singleUrl = baseurl + singleUrl; + } + const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息 + // ### 判断缓存是否存在,如果存在即跳过此次获取的信息 + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + // 获取详情页面的介绍 + const detail_response = await got({ + method: 'get', + url: singleUrl, + }); + const $ = cheerio.load(detail_response.data); + const detail_content = $('div.contain > div.main > div.right_cont > article').html(); + // ### 设置 RSS feed item + const single = { + title: title, + link: singleUrl, + // author: author, + description: detail_content, + // pubDate: updateDate, + }; + // // ### 设置缓存 + ctx.cache.set(singleUrl, JSON.stringify(single)); + return Promise.resolve(single); + // } + }) + ); + + ctx.state.data = { + title: HEAD[type] + `-计算机科学与技术学院`, + link: baseurl + MAP[type] + '.htm', + description: HEAD[type] + `-计算机科学与技术学院`, + item: out, + }; +}; diff --git a/lib/routes/universities/upc/main.js b/lib/routes/universities/upc/main.js new file mode 100644 index 0000000000..0212d1fe16 --- /dev/null +++ b/lib/routes/universities/upc/main.js @@ -0,0 +1,72 @@ +// 学校官网:http://www.upc.edu.cn/ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const baseurl = 'http://news.upc.edu.cn/'; +// 地址映射 +const MAP = { + notice: 'tzgg', + scholar: 'xsdt', +}; +// 头部信息 +const HEAD = { + notice: '通知公告', + scholar: '学术动态', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type; + const response = await got({ + method: 'get', + url: baseurl + MAP[type] + '.htm', + }); + const $ = cheerio.load(response.data); + // ## 获取列表 + const list = $('div.container > div.main-ny > div.main-ny-cont > div.main-ny-cont-box > div.main-list-box > div.main-list-box-left > ul > li > div.li-right > div.li-right-bt > a').get(); + // ## 定义输出的item + const out = await Promise.all( + // ### 遍历列表,筛选出自己想要的内容 + list.map(async (item) => { + const itemSingle = cheerio.load(item); + const title = itemSingle.text(); + const re = /]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g; + let singleUrl = ''; + if (re.exec(itemSingle.html()) !== null) { + singleUrl = RegExp.$1; + } + if (singleUrl.search('http') === -1) { + singleUrl = `http://news.upc.edu.cn/` + singleUrl; + } + const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息 + // ### 判断缓存是否存在,如果存在即跳过此次获取的信息 + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + // 获取详情页面的介绍 + const detail_response = await got({ + method: 'get', + url: singleUrl, + }); + const $ = cheerio.load(detail_response.data); + const detail_content = $('div.container > div.main-ny > div.main-ny-cont > div.main-ny-cont-box > div.main-content-box > form').html(); + // ### 设置 RSS feed item + const single = { + title: title, + link: singleUrl, + // author: author, + description: detail_content, + // pubDate: updateDate, + }; + // // ### 设置缓存 + ctx.cache.set(singleUrl, JSON.stringify(single)); + return Promise.resolve(single); + // } + }) + ); + + ctx.state.data = { + title: HEAD[type] + `-中国石油大学(华东)`, + link: baseurl + MAP[type] + '.htm', + description: HEAD[type] + `-中国石油大学(华东)`, + item: out, + }; +};