From 0be537f80c3197bdce5e67955826259adf8f3911 Mon Sep 17 00:00:00 2001 From: ChangT <62007509+chang4tech@users.noreply.github.com> Date: Fri, 18 Dec 2020 10:33:18 -0600 Subject: [PATCH] feat: add UTDallas ISSO news (#6458) --- docs/university.md | 6 +++ lib/router.js | 3 ++ lib/routes/universities/utdallas/isso.js | 59 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/routes/universities/utdallas/isso.js diff --git a/docs/university.md b/docs/university.md index a294c8beaa..aed854883b 100644 --- a/docs/university.md +++ b/docs/university.md @@ -28,6 +28,12 @@ pageClass: routes +## UTDallas + +### International Student Services + + + ## 安徽工业大学 ### 教务处 diff --git a/lib/router.js b/lib/router.js index dce70e035f..a38fcbd0c2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/universities/utdallas/isso.js b/lib/routes/universities/utdallas/isso.js new file mode 100644 index 0000000000..91394e6883 --- /dev/null +++ b/lib/routes/universities/utdallas/isso.js @@ -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, + }; +};