feat: 增加安徽医科大学研究生学院通知公告 (#4445) (#4492)

This commit is contained in:
Origami404
2020-04-19 19:10:35 +08:00
committed by GitHub
parent 8edbad8164
commit 9ef3943d04
3 changed files with 60 additions and 0 deletions

View File

@@ -24,6 +24,12 @@ pageClass: routes
<Route author="exuanbo" example="/polimi/news" path="/polimi/news/:language?" :paramsDesc="['English language code en']" />
## 安徽医科大学
### 研究生学院通知公告
<Route author="Origami404" example="/ahmu/news" path="/ahmu/news" />
## 北华航天工业学院
### 新闻

View File

@@ -765,6 +765,9 @@ router.get('/ncwu/notice', require('./routes/universities/ncwu/notice'));
// 中北大学
router.get('/nuc/:type', require('./routes/universities/nuc/index'));
// 安徽医科大学研究生学院
router.get('/ahmu/news', require('./routes/universities/ahmu/news'));
// ifanr
router.get('/ifanr/:channel?', require('./routes/ifanr/index'));

View File

@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const date = require('@/utils/date');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'http://yjsxy.ahmu.edu.cn/_s62/1840/list.psp';
const response = await got({ method: 'get', url });
const $ = cheerio.load(response.data);
const list = $('#wp_news_w3 table tbody')
.map((i, e) => {
const element = $(e);
const title = element.find('a').text();
const link = element.find('a').attr('href');
const dateraw = /(\d{4})\/(\d{2})(\d{2})/.exec(link);
return {
title: title,
description: '',
link: url + link,
author: '安徽医科大学研究生学院',
pubDate: date(`${dateraw[1]}-${dateraw[2]}-${dateraw[3]}`),
};
})
.get();
const result = await Promise.all(
list.map(async (item) => {
const link = item.link;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const itemReponse = await got.get(link);
const itemElement = cheerio.load(itemReponse.data);
item.description = itemElement('.content').html();
ctx.cache.set(link, JSON.stringify(item));
return Promise.resolve(item);
})
);
ctx.state.data = {
title: '安徽医科大学研究生学院',
link: url,
item: result,
};
};