feat: 大幅优化中国地质大学路由 (#6140)

This commit is contained in:
Dorad
2020-11-12 23:49:29 +08:00
committed by GitHub
parent 7a2faa74ad
commit 57c232f10a
7 changed files with 195 additions and 4 deletions

View File

@@ -1930,6 +1930,10 @@ type 列表:
## 中国地质大学 (武汉)
### 今日文章-包含全校网站最新通知
<Route author="Dorad" example="/cug/news" path="/cug/news" />
### 研究生院综合通知公告
<Route author="sanmmm" example="/cug/graduate" path="/cug/graduate" />
@@ -1942,6 +1946,14 @@ type 列表:
<Route author="chunibyo-wly" example="/cug/xgxy" path="/cug/xgxy" />
### 工程学院
<Route author="Dorad" example="/cug/gcxy/1" path="/cug/gcxy/:type" />
| 所有 | 学院新闻 | 通知公告 | 党建工作 | 学术动态 | 本科生教育 | 研究生教育 | 教工之家 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
## 中国海洋大学
### 信息科学与工程学院

View File

@@ -2171,10 +2171,12 @@ router.get('/chuiniu/column_list', require('./routes/chuiniu/column_list'));
// leemeng
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('/cug/graduate', require('./routes/universities/cug/graduate'));
router.get('/cug/undergraduate', require('./routes/universities/cug/undergraduate'));
router.get('/cug/xgxy', require('./routes/universities/cug/xgxy'));
router.get('/cug/news', require('./routes/universities/cug/news'));
router.get('/cug/gcxy/:type?', require('./routes/universities/cug/gcxy/index'));
// 网易 - 网易号
router.get('/netease/dy/:id', require('./routes/netease/dy'));

View File

@@ -0,0 +1,113 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const host = 'http://gcxy.cug.edu.cn';
const typeUrl = [
{
name: '所有',
url: ''
},
{
name: '学院新闻',
url: '/index/xyxw.htm'
},
{
name: '通知公告',
url: '/index/tzgg.htm'
},
{
name: '党建工作',
url: '/index/djgz.htm'
},
{
name: '学术动态',
url: '/index/xsdt.htm'
},
{
name: '本科生教育',
url: '/index/bksjy.htm'
},
{
name: '研究生教育',
url: '/index/yjsjy.htm'
},
{
name: '教工之家',
url: '/index/jgzj.htm'
}
];
let type = ctx.params && ctx.params.type;
if (type === undefined) {
type = 0;
} else {
type = Number(type);
if (type >= typeUrl.length) {
return false;
}
}
let typeList = [];
if (type === 0) {
// 获取所有的
typeList = Object.keys(Array.apply(null, { length: typeUrl.length }));
} else {
typeList.push(type);
}
// console.log(typeList);
const getItems = async function (url) {
try {
const response = await got({
method: 'get',
url: host + url,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const items = $('div.right_list > ul > li');
return await Promise.all(
items.map(async (index, item) => {
item = $(item);
const a = item.find('a');
const link = host + a.attr('href').replace('..', '');
// console.log(link);
return {
title: a.attr('title'),
link: link,
description: await got({
method: 'get',
url: link,
headers: {
Referer: host,
},
}).then((res) => {
const $ = cheerio.load(res.data);
return $('.v_news_content').html();
}).catch(() => ''),
pubDate: item.find('span').text(),
};
}).get()
);
} catch (e) {
return [];
}
};
const outList = await Promise.all(
typeList
.map(async (t) => await getItems(typeUrl[t].url))
);
ctx.state.data = {
title: '[' + typeUrl[type].name + ']' + 'CUG-工程学院',
link: host + typeUrl[type].url,
description: '中国地质大学(武汉)工程学院-' + typeUrl[type].name,
item: outList.reduce((p, n) => p.concat(n))
};
};

View File

@@ -0,0 +1,64 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
// 发起 HTTP GET 请求
const host = 'http://xxhb.cug.edu.cn/zqxt/zqjsjg.jsp?wbtreeid=1283&selectType=1&searchScope=0';
const response = await got({
method: 'get',
url: host,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('form[id=searchlistform1] > table.listFrame > tbody > tr > td');
const results = [];
let item = {};
for (let i = 0; i < list.length; i++) {
const d = $(list[i]);
d.find('i').remove();
const title = d.find('span.titlefontstyle206274');
const from = d.find('span.sourcesitefontstyle206274');
const description = d.find('span.contentfontstyle206274');
const time = d.find('span.timefontstyle206274');
if (title.length) {
item.title = from.text() + title.text();
item.link = d.find('a').attr('href');
} else if (description.length) {
item.description = item.description ? item.description + d.text() : d.text();
} else if (time.length) {
item.pubDate = new Date(time.text().replace('发表时间:', '').replace('年', '-').replace('月', '-').replace('日', '')).toUTCString();
results.push(item);
item = {};
}
}
let out = await Promise.all(
results
.map(async (element) => {
const link = element.link;
try {
const result = await got.get(link);
const $ = cheerio.load(result.data);
element.description = $('.v_news_content').html();
element.enabled = true;
} catch (e) {
element.enabled = false;
}
return Promise.resolve(element);
})
);
out = out.filter((item) => item.enabled === true);
ctx.state.data = {
title: 'CUG-今日文章',
link: host,
description: '中国地质大学(武汉) 每日文章,几乎包含全校站点最新信息。',
item: out,
};
};