diff --git a/docs/university.md b/docs/university.md index 2ead7d73d..aaffea3ad 100644 --- a/docs/university.md +++ b/docs/university.md @@ -24,6 +24,38 @@ pageClass: routes +## 安徽农业大学 + +### 计算机学院 + + + +| 信息通告 | 新闻动态 | +| -------- | -------- | +| xxtg | xwddyn | + + + +### 教务处 + + + +| 教务要闻 | 通知公告 | +| -------- | -------- | +| jwyw | tzgg | + + + +### 安农大官网新闻 + + + +| 校内要闻 | 学院动态 | +| -------- | -------- | +| xnyw | xydt | + + + ## 安徽医科大学 ### 研究生学院通知公告 diff --git a/lib/router.js b/lib/router.js index ac13d012e..221136096 100644 --- a/lib/router.js +++ b/lib/router.js @@ -783,6 +783,11 @@ router.get('/ncwu/notice', require('./routes/universities/ncwu/notice')); // 中北大学 router.get('/nuc/:type', require('./routes/universities/nuc/index')); +// 安徽农业大学 +router.get('/ahau/cs_news/:type', require('./routes/universities/ahau/cs_news/index')); +router.get('/ahau/jwc/:type', require('./routes/universities/ahau/jwc/index')); +router.get('/ahau/main/:type', require('./routes/universities/ahau/main/index')); + // 安徽医科大学研究生学院 router.get('/ahmu/news', require('./routes/universities/ahmu/news')); diff --git a/lib/routes/universities/ahau/cs_news/index.js b/lib/routes/universities/ahau/cs_news/index.js new file mode 100644 index 000000000..b571a3c62 --- /dev/null +++ b/lib/routes/universities/ahau/cs_news/index.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'xxtg': + title = '信息通告'; + path = 'xxtg.htm'; + break; + case 'xwddyn': + title = '新闻动态'; + path = 'xwddyn.htm'; + break; + } + + const response = await got({ + method: 'get', + url: 'http://computer.ahau.edu.cn/xyxub/' + path, + headers: { + Referer: 'http://computer.ahau.edu.cn/index.htm', + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.n_right .n_listxx1 .cleafix').slice(0, 15).get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '安徽农业大学计算机学院 - ' + title, + link: 'http://computer.ahau.edu.cn/xyxub/' + path, + description: '安徽农业大学计算机学院 - ' + title, + item: result, + }; +}; diff --git a/lib/routes/universities/ahau/cs_news/utils.js b/lib/routes/universities/ahau/cs_news/utils.js new file mode 100644 index 000000000..24f071a5a --- /dev/null +++ b/lib/routes/universities/ahau/cs_news/utils.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + // DATE + const date = new Date( + $('div.contain > form > h3 span:nth-of-type(1)') + .text() + .match(/\d{4}-\d{2}-\d{2}/) + ); + const timeZone = 8; + const serverOffset = date.getTimezoneOffset() / 60; + const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); + + const description = $('#vsb_content > .v_news_content').html(); + + return { description, pubDate }; +} + +const ProcessFeed = async (list, caches) => { + const host = 'http://computer.ahau.edu.cn/'; + + return await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title = $('a'); + const itemUrl = url.resolve(host, $title.attr('href')); + + const single = { + title: $title.text(), + link: itemUrl, + author: '安农大信息与计算机学院', + guid: itemUrl, + }; + + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +}; + +module.exports = { + ProcessFeed, +}; diff --git a/lib/routes/universities/ahau/jwc/index.js b/lib/routes/universities/ahau/jwc/index.js new file mode 100644 index 000000000..53d2cd249 --- /dev/null +++ b/lib/routes/universities/ahau/jwc/index.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'jwyw': + title = '教务要闻'; + path = 'jwyw.htm'; + break; + case 'tzgg': + title = '通知公告'; + path = 'tzgg.htm'; + break; + } + + const response = await got({ + method: 'get', + url: 'http://jwc.ahau.edu.cn/' + path, + headers: { + Referer: 'http://jwc.ahau.edu.cn/jwyw.htm', + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.pageList li .clearfix').slice(0, 20).get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '安徽农业大学教务处 - ' + title, + link: 'http://jwc.ahau.edu.cn/' + path, + description: '安徽农业大学教务处 - ' + title, + item: result, + }; +}; diff --git a/lib/routes/universities/ahau/jwc/utils.js b/lib/routes/universities/ahau/jwc/utils.js new file mode 100644 index 000000000..fa1a06a25 --- /dev/null +++ b/lib/routes/universities/ahau/jwc/utils.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const date = new Date( + $('.introTime span:nth-of-type(2)') + .text() + .match(/\d{4}-\d{2}-\d{2}/) + ); + const timeZone = 8; + const serverOffset = date.getTimezoneOffset() / 60; + const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); + + const description = $('#vsb_content > .v_news_content').html(); + + return { description, pubDate }; +} + +const ProcessFeed = async (list, caches) => { + const host = 'http://jwc.ahau.edu.cn/'; + + return await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title = $('a'); + const $title_pretty = $title.attr('title').trim(); + const itemUrl = url.resolve(host, $title.attr('href')); + + const single = { + title: $title_pretty, + link: itemUrl, + author: '安农大教务处', + guid: itemUrl, + }; + + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +}; + +module.exports = { + ProcessFeed, +}; diff --git a/lib/routes/universities/ahau/main/index.js b/lib/routes/universities/ahau/main/index.js new file mode 100644 index 000000000..e0782c92a --- /dev/null +++ b/lib/routes/universities/ahau/main/index.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'xnyw': + title = '校内要闻'; + path = 'xnyw.htm'; + break; + case 'xydt': + title = '学院动态'; + path = 'xydt.htm'; + break; + } + + const response = await got({ + method: 'get', + url: 'http://news.ahau.edu.cn/' + path, + headers: { + Referer: 'http://news.ahau.edu.cn/', + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.listbox .title').slice(0, 10).get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '安徽农业大学新闻网 - ' + title, + link: 'http://news.ahau.edu.cn/' + path, + description: '安徽农业大学新闻网 - ' + title, + item: result, + }; +}; diff --git a/lib/routes/universities/ahau/main/utils.js b/lib/routes/universities/ahau/main/utils.js new file mode 100644 index 000000000..692b14641 --- /dev/null +++ b/lib/routes/universities/ahau/main/utils.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const date = new Date( + $('.info') + .text() + .match(/\d{4}-\d{2}-\d{2}/) + ); + const timeZone = 8; + const serverOffset = date.getTimezoneOffset() / 60; + const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); + + const description = $('#vsb_content > .v_news_content').html(); + + return { description, pubDate }; +} + +const ProcessFeed = async (list, caches) => { + const host = 'http://news.ahau.edu.cn/'; + + return await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title_href = $('a'); + const $title = $('a span').text().trim(); + const itemUrl = url.resolve(host, $title_href.attr('href')); + + const single = { + title: $title, + link: itemUrl, + author: '安农大新闻', + guid: itemUrl, + }; + + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + return Promise.resolve(Object.assign({}, single, other)); + }) + ); +}; + +module.exports = { + ProcessFeed, +};