From 501ab2c4e657cea05789a21ad457354f7bdeaae5 Mon Sep 17 00:00:00 2001 From: Haoran Liu <1051276278@qq.com> Date: Fri, 22 May 2020 00:16:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=93=88=E5=B0=94=E6=BB=A8?= =?UTF-8?q?=E5=B7=A5=E4=B8=9A=E5=A4=A7=E5=AD=A6=EF=BC=88=E5=A8=81=E6=B5=B7?= =?UTF-8?q?=EF=BC=89=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#4825)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 6 ++++ lib/router.js | 3 ++ lib/routes/universities/hitwh/today.js | 47 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/universities/hitwh/today.js diff --git a/docs/university.md b/docs/university.md index 579146e31..dc99cdb76 100644 --- a/docs/university.md +++ b/docs/university.md @@ -551,6 +551,12 @@ category 列表: 部分文章需要经过统一身份认证后才能阅读全文。 ::: +## 哈尔滨工业大学(威海) + +### 今日工大 - 通知公告 + + + ## 河南大学 ### 河南大学 diff --git a/lib/router.js b/lib/router.js index e634486fa..1ec7379fc 100644 --- a/lib/router.js +++ b/lib/router.js @@ -585,6 +585,9 @@ router.get('/nuaa/yjsy/:type?', require('./routes/universities/nuaa/yjsy/yjsy')) router.get('/hit/jwc', require('./routes/universities/hit/jwc')); router.get('/hit/today/:category', require('./routes/universities/hit/today')); +// 哈尔滨工业大学(威海) +router.get('/hitwh/today', require('./routes/universities/hitwh/today')); + // 上海科技大学 router.get('/shanghaitech/activity', require('./routes/universities/shanghaitech/activity')); router.get('/shanghaitech/sist/activity', require('./routes/universities/shanghaitech/sist/activity')); diff --git a/lib/routes/universities/hitwh/today.js b/lib/routes/universities/hitwh/today.js new file mode 100644 index 000000000..db41f31c3 --- /dev/null +++ b/lib/routes/universities/hitwh/today.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +const baseUrl = 'http://today.hitwh.edu.cn'; + +module.exports = async (ctx) => { + const response = await got.get(`${baseUrl}/1024/list.htm`); + const { data } = response; + const $ = cheerio.load(data); + const type = (filename) => filename.split('.').pop(); + const links = $('#righ_list ul li') + .map((_, el) => ({ + pubDate: new Date($(el).find('font').text().substr(-10, 10)).toUTCString(), + link: url.resolve(baseUrl, $('a', el).attr('href')), + title: $(el).find('a').text(), + })) + .get(); + + ctx.state.data = { + title: '哈尔滨工业大学(威海)通知公告', + link: `${baseUrl}/1024/list.htm`, + item: await Promise.all( + links.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + if (type(item.link) === 'htm') { + const { data } = await got.get(item.link); + const $ = cheerio.load(data); + item.description = + $('div.wp_articlecontent').html() && + $('div.wp_articlecontent') + .html() + .replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`) + .replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`) + .trim(); + return item; + } else { + // file to download + item.description = '此链接为文件,点击以下载'; + return item; + } + }) + ) + ), + }; +};