From d24db95f06fb41543a4d9e00e785a5142589e9ce Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:42:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E9=82=AE=E7=94=B5=E5=A4=A7=E5=AD=A6=E4=BA=BA=E6=89=8D=E6=8B=9B?= =?UTF-8?q?=E8=81=98=20(#8438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 4 +++ lib/v2/bupt/maintainer.js | 3 +++ lib/v2/bupt/radar.js | 13 ++++++++++ lib/v2/bupt/rczp.js | 51 +++++++++++++++++++++++++++++++++++++++ lib/v2/bupt/router.js | 3 +++ 5 files changed, 74 insertions(+) create mode 100644 lib/v2/bupt/maintainer.js create mode 100644 lib/v2/bupt/radar.js create mode 100644 lib/v2/bupt/rczp.js create mode 100644 lib/v2/bupt/router.js diff --git a/docs/university.md b/docs/university.md index cbb03e4aa..a937d0f7f 100644 --- a/docs/university.md +++ b/docs/university.md @@ -283,6 +283,10 @@ pageClass: routes ::: +### 人才招聘 + + + ## 常州大学 ### 教务处 diff --git a/lib/v2/bupt/maintainer.js b/lib/v2/bupt/maintainer.js new file mode 100644 index 000000000..1a48219f7 --- /dev/null +++ b/lib/v2/bupt/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/rczp': ['nczitzk'], +}; diff --git a/lib/v2/bupt/radar.js b/lib/v2/bupt/radar.js new file mode 100644 index 000000000..0a9c2df63 --- /dev/null +++ b/lib/v2/bupt/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'bupt.edu.cn': { + _name: '北京邮电大学', + '.': [ + { + title: '人才招聘', + docs: 'https://docs.rsshub.app/university.html#bei-jing-you-dian-da-xue-ren-cai-zhao-pin', + source: ['/'], + target: '/bupt/rczp', + }, + ], + }, +}; diff --git a/lib/v2/bupt/rczp.js b/lib/v2/bupt/rczp.js new file mode 100644 index 000000000..017115538 --- /dev/null +++ b/lib/v2/bupt/rczp.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.bupt.edu.cn'; + const currentUrl = `${rootUrl}/rczp.htm`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.date-block') + .map((_, item) => { + item = $(item); + + return { + title: item.next().text(), + link: `${rootUrl}/${item.next().attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.v_news_content').html(); + item.pubDate = timezone(parseDate(content('.info span').first().text().replace('发布时间 : ', '')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/bupt/router.js b/lib/v2/bupt/router.js new file mode 100644 index 000000000..44d728461 --- /dev/null +++ b/lib/v2/bupt/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/rczp', require('./rczp')); +};