From 28aa9e6703e26ec5cb6d1b4499e418b34273a462 Mon Sep 17 00:00:00 2001 From: fox2049 <60031998+fox2049@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20add=20=E4=B8=9C=E5=8D=8E?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6=E7=94=9F=E6=8B=9B=E7=94=9F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20(dhu/yjs/zs)=20(#12596)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add yjszs info of dhu * change order and add zs make * 4 spaces for indentation, camelCase, del utf-8 decoder, link to string * code proofreading * delete got params * update link code * delete link body in ctx.state.data * Update lib/v2/dhu/maintainer.js --------- Co-authored-by: Yuexin Sun --- docs/university.md | 10 ++++++++++ lib/v2/dhu/maintainer.js | 1 + lib/v2/dhu/radar.js | 6 ++++++ lib/v2/dhu/router.js | 1 + lib/v2/dhu/yjs/zs.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 lib/v2/dhu/yjs/zs.js diff --git a/docs/university.md b/docs/university.md index 9df28b988..56125a943 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1011,6 +1011,16 @@ pageClass: routes +### 研究生招生信息 + + + +| 博士招生 | 硕士招生 | +| -------- | -------- | +| doctor | master | + + + ## 东南大学 ### 信息科学与工程学院学术活动 diff --git a/lib/v2/dhu/maintainer.js b/lib/v2/dhu/maintainer.js index 4993d1b37..28fd3315c 100644 --- a/lib/v2/dhu/maintainer.js +++ b/lib/v2/dhu/maintainer.js @@ -1,4 +1,5 @@ module.exports = { '/jiaowu/news/:type?': ['KiraKiseki'], '/xxgk/news': ['KiraKiseki'], + '/yjs/zs/:type?': ['fox2049'], }; diff --git a/lib/v2/dhu/radar.js b/lib/v2/dhu/radar.js index a99cdd9cc..e91e94183 100644 --- a/lib/v2/dhu/radar.js +++ b/lib/v2/dhu/radar.js @@ -13,5 +13,11 @@ module.exports = { docs: 'https://docs.rsshub.app/university.html#dong-hua-da-xue', }, ], + yjs: [ + { + title: '研究生信息', + docs: 'https://docs.rsshub.app/university.html#dong-hua-da-xue', + }, + ], }, }; diff --git a/lib/v2/dhu/router.js b/lib/v2/dhu/router.js index 11dfa6b54..2f13d9e85 100644 --- a/lib/v2/dhu/router.js +++ b/lib/v2/dhu/router.js @@ -1,4 +1,5 @@ module.exports = function (router) { router.get('/jiaowu/news/:type?', require('./jiaowu/news')); router.get('/xxgk/news', require('./xxgk/news')); + router.get('/yjs/zs/:type?', require('./yjs/zs')); }; diff --git a/lib/v2/dhu/yjs/zs.js b/lib/v2/dhu/yjs/zs.js new file mode 100644 index 000000000..cb747a744 --- /dev/null +++ b/lib/v2/dhu/yjs/zs.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timeZone = require('@/utils/timezone'); + +const baseUrl = 'https://yjszs.dhu.edu.cn'; + +const map = { + doctor: '/7126/list.htm', + master: '/7128/list.htm', +}; +module.exports = async (ctx) => { + const type = ctx.params.type || 'master'; + const link = `${baseUrl}${map[type]}`; + const { data: response } = await got(link); + + const $ = cheerio.load(response); + + const items = $('.list_item') + .map((_, elem) => ({ + link: new URL($('a', elem).attr('href'), baseUrl).href, + title: $('a', elem).attr('title'), + pubDate: timeZone(parseDate($('.Article_PublishDate', elem).text()), +8), + })) + .get(); + + ctx.state.data = { + title: '东华大学研究生-' + $('.col_title').text(), + link, + item: items, + }; +};