From f7f8b7a8e71c15879d401f146a305f833db9c875 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 15 Dec 2023 17:23:01 +0000 Subject: [PATCH] feat(route): sspu (#14050) --- lib/v2/sspu/jwc.js | 44 ++++++++++++++++++++++++++++++ lib/v2/sspu/maintainer.js | 3 ++ lib/v2/sspu/radar.js | 13 +++++++++ lib/v2/sspu/router.js | 3 ++ website/docs/routes/university.mdx | 10 +++++++ 5 files changed, 73 insertions(+) create mode 100644 lib/v2/sspu/jwc.js create mode 100644 lib/v2/sspu/maintainer.js create mode 100644 lib/v2/sspu/radar.js create mode 100644 lib/v2/sspu/router.js diff --git a/lib/v2/sspu/jwc.js b/lib/v2/sspu/jwc.js new file mode 100644 index 00000000000000..209cd2435f0016 --- /dev/null +++ b/lib/v2/sspu/jwc.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const { listId } = ctx.params; + const baseUrl = 'https://jwc.sspu.edu.cn'; + + const { data: response, url: link } = await got(`${baseUrl}/${listId}/list.htm`); + const $ = cheerio.load(response); + + const list = $('.news_list .news') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15) + .toArray() + .map((item) => { + item = $(item); + const title = item.find('.news_title a'); + return { + title: title.attr('title'), + link: `${baseUrl}${title.attr('href')}`, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + item.description = $('.wp_articlecontent').html(); + item.pubDate = timezone(parseDate($('.arti_update').text(), 'YYYY-MM-DD HH:mm:ss'), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link, + item: items, + }; +}; diff --git a/lib/v2/sspu/maintainer.js b/lib/v2/sspu/maintainer.js new file mode 100644 index 00000000000000..7ddb6347a5d476 --- /dev/null +++ b/lib/v2/sspu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/jwc/:listId': ['TonyRL'], +}; diff --git a/lib/v2/sspu/radar.js b/lib/v2/sspu/radar.js new file mode 100644 index 00000000000000..b0c3b76645b893 --- /dev/null +++ b/lib/v2/sspu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sspu.edu.cn': { + _name: '上海第二工业大学', + jwc: [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/university#shang-hai-di-er-gong-ye-da-xue', + source: ['/jwc/:listId/list.htm'], + target: '/sspu/jwc/:listId', + }, + ], + }, +}; diff --git a/lib/v2/sspu/router.js b/lib/v2/sspu/router.js new file mode 100644 index 00000000000000..fa4184a46a1eb6 --- /dev/null +++ b/lib/v2/sspu/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/jwc/:listId', require('./jwc')); +}; diff --git a/website/docs/routes/university.mdx b/website/docs/routes/university.mdx index 0accaaa82ffa76..cf1928b10ab654 100644 --- a/website/docs/routes/university.mdx +++ b/website/docs/routes/university.mdx @@ -2335,6 +2335,16 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE\_TL | notice | news | policy | +## 上海第二工业大学 {#shang-hai-di-er-gong-ye-da-xue} + +### 教务处 {#shang-hai-di-er-gong-ye-da-xue-jiao-wu-chu} + + + | 学生专栏 | 教师专栏 | + | -------- | -------- | + | 897 | 898 | + + ## 上海电力大学 {#shang-hai-dian-li-da-xue} ### 新闻网与学院通知 {#shang-hai-dian-li-da-xue-xin-wen-wang-yu-xue-yuan-tong-zhi}