feat: 添加了中国地质大学及地理与信息工程学院的通知公告 (#4927)

This commit is contained in:
Chunibyo
2020-06-09 11:24:20 +08:00
committed by GitHub
parent d274c8ee08
commit ddf5b0d004
4 changed files with 131 additions and 0 deletions
+8
View File
@@ -1681,6 +1681,14 @@ type 列表:
<Route author="sanmmm" example="/cug/graduate" path="/cug/graduate" />
### 中国地质大学通知公告
<Route author="chunibyo-wly" example="/cug/undergraduate" path="/cug/undergraduate" />
### 地理与信息工程学院综合通知公告
<Route author="chunibyo-wly" example="/cug/xgxy" path="/cug/xgxy" />
## 中国海洋大学
### 信息科学与工程学院
+2
View File
@@ -2032,6 +2032,8 @@ router.get('/leemeng', require('./routes/blogs/leemeng'));
// 中国地质大学
router.get('/cug/graduate', require('./routes/cug/graduate'));
router.get('/cug/undergraduate', require('./routes/cug/undergraduate'));
router.get('/cug/xgxy', require('./routes/cug/xgxy'));
// 网易 - 网易号
router.get('/netease/dy/:id', require('./routes/netease/dy'));
+86
View File
@@ -0,0 +1,86 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
// 发起 HTTP GET 请求
const baseUrl = 'http://www.cug.edu.cn/index/tzgg.htm';
const response = await got({
method: 'get',
url: baseUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('#container > div > div > div.col-news > div.col-news-con > ul > li');
const out = await Promise.all(
list
.map(async (index, element) => {
element = $(element);
const link = element.find('a').attr('href');
const description = await ctx.cache.tryGet(link, async () => {
const result = await got.get(link[0] === '.' ? `${baseUrl}/../${link}` : link);
const $ = cheerio.load(result.data);
return $('.read').html();
});
const item = {
title: element.find('a').text(),
link: link,
pubDate: new Date(element.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(),
description: description,
};
return Promise.resolve(item);
})
.get()
);
ctx.state.data = {
title: '中国地质大学(武汉) - 综合通知公告',
link: baseUrl,
item: out,
};
/*
async function getDescription(_link) {
try {
const response = await got({
method: 'get',
url: _link[0] === '.' ? `${baseUrl}/../${_link}` : _link,
});
const data = response.data;
const $ = cheerio.load(data);
return $('.read span').text();
} catch (e) {
return '未取到数据';
}
}
const descriptionPromises = list.map((index, item) => getDescription($(item).find('a').attr('href'))).get();
const descriptions = await Promise.all(descriptionPromises);
ctx.state.data = {
title: '中国地质大学(武汉) - 综合通知公告',
link: baseUrl,
item:
list &&
list
.map((index, item) => {
item = $(item);
const _link = item.find('a').attr('href');
return {
title: item.find('a').text(),
link: _link,
pubDate: new Date(item.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(),
description: descriptions[index],
};
})
.get(),
};
*/
};
+35
View File
@@ -0,0 +1,35 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
// 发起 HTTP GET 请求
const baseUrl = 'http://xgxy.cug.edu.cn/index/tzgg.htm';
const response = await got({
method: 'get',
url: baseUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('#content > section.section.full-width-bg.gray-bg > div > div > div > ul > li');
ctx.state.data = {
title: '中国地质大学(武汉)地理与信息工程学院 - 综合通知公告',
link: baseUrl,
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').text(),
link: item.find('a').attr('href'),
pubDate: new Date(item.find('span').text().replace('年', '-').replace('月', '-').replace('日', '')).toUTCString(),
};
})
.get(),
};
};