From aedf5c8cb7fe2ccd4cb22e58b558f84641137d27 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Thu, 1 Sep 2022 23:23:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=AD=A6=E5=B7=A5?= =?UTF-8?q?=E9=83=A8=20(#10673)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 学工部 * Update lib/v2/bnu/dwxgb.js --- docs/university.md | 10 ++++++++ lib/v2/bnu/dwxgb.js | 57 ++++++++++++++++++++++++++++++++++++++++++++ lib/v2/bnu/radar.js | 8 ++++++- lib/v2/bnu/router.js | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 lib/v2/bnu/dwxgb.js diff --git a/docs/university.md b/docs/university.md index eba308673..1a3f5beea 100644 --- a/docs/university.md +++ b/docs/university.md @@ -288,6 +288,16 @@ pageClass: routes +### 党委学生工作部 + + + +`https://dwxgb.bnu.edu.cn/xwzx/tzgg/index.html`\ +则对应为\ +`/bnu/dwxgb/xwzx/tzgg` + + + ### 信息学院通知 diff --git a/lib/v2/bnu/dwxgb.js b/lib/v2/bnu/dwxgb.js new file mode 100644 index 000000000..ae224b8c3 --- /dev/null +++ b/lib/v2/bnu/dwxgb.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category, type } = ctx.params; + + const rootUrl = 'https://dwxgb.bnu.edu.cn'; + let currentUrl = `${rootUrl}/${category}/${type}/index.html`; + + let response; + try { + response = await got({ + method: 'get', + url: currentUrl, + }); + } catch (e) { + currentUrl = `${rootUrl}/${category}/${type}/index.htm`; + response = await got({ + method: 'get', + url: currentUrl, + }); + } + + const $ = cheerio.load(response.data); + + const list = $('ul.container.list > li') + .map((_, item) => ({ + title: $(item).find('a').text().trim(), + pubDate: parseDate($(item).find('span').text()), + link: `${rootUrl}/${category}/${type}/${$(item).find('a').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('div.article.typo').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('div.breadcrumb1 > a:nth-child(3)').text()} - ${$('div.breadcrumb1 > a:nth-child(4)').text()}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/bnu/radar.js b/lib/v2/bnu/radar.js index c82302c19..471cb5c95 100644 --- a/lib/v2/bnu/radar.js +++ b/lib/v2/bnu/radar.js @@ -4,10 +4,16 @@ module.exports = { '.': [ { title: '经济与工商管理学院', - docs: 'https://docs.rsshub.app/universities.html#bei-jing-shi-fan-da-xue-jing-ji-yu-gong-shang-guan-li-xue-yuan', + docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', source: ['/'], target: '/bs/:category?', }, + { + title: '经济与工商管理学院', + docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', + source: ['/'], + target: '/bnu/dwxgb/:category/:type', + }, ], }, }; diff --git a/lib/v2/bnu/router.js b/lib/v2/bnu/router.js index 8435cd362..e605fe286 100644 --- a/lib/v2/bnu/router.js +++ b/lib/v2/bnu/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/bs/:category?', require('./bs')); + router.get('/dwxgb/:category/:type', require('./dwxgb')); };