feat: 增加安农大RSS (#4800)

This commit is contained in:
SimonHu
2020-05-18 12:36:13 +08:00
committed by GitHub
parent 223d9a5356
commit dddd964138
8 changed files with 304 additions and 0 deletions
+32
View File
@@ -24,6 +24,38 @@ pageClass: routes
<Route author="exuanbo" example="/polimi/news" path="/polimi/news/:language?" :paramsDesc="['English language code en']" />
## 安徽农业大学
### 计算机学院
<Route author="SimonHu-HN" example="/ahau/cs_news/xxtg" path="/ahau/cs_news/:type" :paramsDesc="['类型名']">
| 信息通告 | 新闻动态 |
| -------- | -------- |
| xxtg | xwddyn |
</Route>
### 教务处
<Route author="SimonHu-HN" example="/ahau/jwc/jwyw" path="/ahau/jwc/:type" :paramsDesc="['类型名']">
| 教务要闻 | 通知公告 |
| -------- | -------- |
| jwyw | tzgg |
</Route>
### 安农大官网新闻
<Route author="SimonHu-HN" example="/ahau/main/xnyw" path="/ahau/main/:type" :paramsDesc="['类型名']">
| 校内要闻 | 学院动态 |
| -------- | -------- |
| xnyw | xydt |
</Route>
## 安徽医科大学
### 研究生学院通知公告
+5
View File
@@ -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'));
@@ -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,
};
};
@@ -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,
};
+39
View File
@@ -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,
};
};
+50
View File
@@ -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,
};
@@ -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,
};
};
@@ -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,
};