Skip to content

Commit

Permalink
feat: add UTDallas ISSO news (#6458)
Browse files Browse the repository at this point in the history
  • Loading branch information
chang4tech committed Dec 18, 2020
1 parent 27e3489 commit 0be537f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

## 安徽工业大学

### 教务处
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
59 changes: 59 additions & 0 deletions lib/routes/universities/utdallas/isso.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit 0be537f

@vercel
Copy link

@vercel vercel bot commented on 0be537f Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.