-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UTDallas ISSO news (#6458)
- Loading branch information
1 parent
27e3489
commit 0be537f
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
0be537f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: