feat: add UTDallas ISSO news (#6458)

This commit is contained in:
ChangT
2020-12-18 16:33:18 +00:00
committed by GitHub
parent 27e3489fb6
commit 0be537f80c
3 changed files with 68 additions and 0 deletions
+6
View File
@@ -28,6 +28,12 @@ pageClass: routes
<Route author="exuanbo" example="/polimi/news" path="/polimi/news/:language?" :paramsDesc="['English language code en']" />
## UTDallas
### International Student Services
<Route author="Chang4Tech" example="/utdallas/isso" path="/utdallas/isso" />
## 安徽工业大学
### 教务处
+3
View File
@@ -698,6 +698,9 @@ router.get('/cuc/yz', require('./routes/universities/cuc/yz'));
router.get('/ustc/news/:type?', require('./routes/universities/ustc/index'));
router.get('/ustc/jwc/:type?', require('./routes/universities/ustc/jwc/index'));
// UTdallas ISSO
router.get('/utdallas/isso', require('./routes/universities/utdallas/isso'));
// 南京邮电大学
router.get('/njupt/jwc/:type?', require('./routes/universities/njupt/jwc'));
+59
View File
@@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const notice_type = {
isso: { title: 'UTDallas - International Student Services', url: 'https://www.utdallas.edu/ic/isso/' },
};
module.exports = async (ctx) => {
// const type = ctx.params.type || 'isso';
const type = 'isso';
// 发起 HTTP GET 请求
const response = await got({
method: 'get',
headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
// cookie: await getCookie(ctx),
},
url: notice_type[type].url,
});
const $ = cheerio.load(response.data);
const list = $('.c6 > p ')
.map(function () {
if ($(this).find('span').text() !== '') {
const info = {
title: $(this).find('span').text(),
description: $(this).next().text(),
// link: ,
// date: new Date().toUTCString(),
};
return info;
} else {
return null;
}
})
.get();
// console.log(list);
const out = await Promise.all(
list.map(async (item) => {
const single = {
title: item.title,
description: item.description,
};
return Promise.resolve(single);
})
);
// console.log(out);
ctx.state.data = {
title: notice_type[type].title,
description: notice_type[type].title,
link: notice_type[type].url,
item: out,
};
};