From 6d78f485766a60ebbc394c253bd35d14669d25b4 Mon Sep 17 00:00:00 2001 From: HyperCherry Date: Fri, 12 May 2023 23:03:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=9B=9B=E5=B7=9D?= =?UTF-8?q?=E5=B7=A5=E5=95=86=E5=AD=A6=E9=99=A2=E5=85=AC=E5=91=8A=20(#1249?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 四川工商学院公告 * Update lib/v2/stbu/xyxw.js * fix(route): adjusted timezone to UTC+8 --------- --- docs/university.md | 14 +++++++++++ lib/v2/stbu/jsjxy.js | 51 ++++++++++++++++++++++++++++++++++++++ lib/v2/stbu/maintainer.js | 4 +++ lib/v2/stbu/radar.js | 21 ++++++++++++++++ lib/v2/stbu/router.js | 4 +++ lib/v2/stbu/xyxw.js | 52 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 lib/v2/stbu/jsjxy.js create mode 100644 lib/v2/stbu/maintainer.js create mode 100644 lib/v2/stbu/radar.js create mode 100644 lib/v2/stbu/router.js create mode 100644 lib/v2/stbu/xyxw.js diff --git a/docs/university.md b/docs/university.md index 1aa2fa31b..fe8a68f20 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2666,6 +2666,20 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +## 四川工商学院 + +### 学院新闻 + + + +### 计算机学院通知公告 + + + +::: warning 注意 +计算机学院通知公告疑似禁止了非大陆IP访问,使用路由需要自行 [部署](https://docs.rsshub.app/install)。 +::: + ## 四川旅游学院 ### 信息与工程学院动态公告列表 diff --git a/lib/v2/stbu/jsjxy.js b/lib/v2/stbu/jsjxy.js new file mode 100644 index 000000000..42884c705 --- /dev/null +++ b/lib/v2/stbu/jsjxy.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const gbk2utf8 = (s) => iconv.decode(s, 'gbk'); +module.exports = async (ctx) => { + const baseUrl = 'https://jsjxy.stbu.edu.cn/news/'; + const { data: response } = await got(baseUrl, { + responseType: 'buffer', + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(gbk2utf8(response)); + const list = $('.content dl h4') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a').first(); + return { + title: a.text(), + link: a.attr('href'), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link, { + responseType: 'buffer', + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(gbk2utf8(response)); + item.description = $('.content14').first().html().trim(); + item.pubDate = timezone(parseDate($('.article .source').text().split('日期:')[1].replace('\n', '').trim()), +8); + return item; + }) + ) + ); + + ctx.state.data = { + title: '四川工商学院计算机学院 - 新闻动态', + link: baseUrl, + description: '四川工商学院计算机学院 - 新闻动态', + item: items, + }; +}; diff --git a/lib/v2/stbu/maintainer.js b/lib/v2/stbu/maintainer.js new file mode 100644 index 000000000..ba5bc6e70 --- /dev/null +++ b/lib/v2/stbu/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/jsjxy': ['HyperCherry'], + '/xyxw': ['HyperCherry'], +}; diff --git a/lib/v2/stbu/radar.js b/lib/v2/stbu/radar.js new file mode 100644 index 000000000..5080d992e --- /dev/null +++ b/lib/v2/stbu/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'stbu.edu.cn': { + _name: '四川工商学院', + '.': [ + { + title: '学院新闻', + docs: 'https://docs.rsshub.app/university.html#si-chuan-gong-shang-xue-yuan', + source: ['/html/news/xueyuan', '/'], + target: '/stbu/xyxw', + }, + ], + jsjxy: [ + { + title: '计算机学院通知公告', + docs: 'https://docs.rsshub.app/university.html#si-chuan-gong-shang-xue-yuan', + source: ['/news', '/'], + target: '/stbu/jsjxy', + }, + ], + }, +}; diff --git a/lib/v2/stbu/router.js b/lib/v2/stbu/router.js new file mode 100644 index 000000000..18d682883 --- /dev/null +++ b/lib/v2/stbu/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/jsjxy', require('./jsjxy')); + router.get('/xyxw', require('./xyxw')); +}; diff --git a/lib/v2/stbu/xyxw.js b/lib/v2/stbu/xyxw.js new file mode 100644 index 000000000..83c13966d --- /dev/null +++ b/lib/v2/stbu/xyxw.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const gbk2utf8 = (s) => iconv.decode(s, 'gbk'); +module.exports = async (ctx) => { + const baseUrl = 'https://www.stbu.edu.cn'; + const requestUrl = `${baseUrl}/html/news/xueyuan/`; + const { data: response } = await got(requestUrl, { + responseType: 'buffer', + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(gbk2utf8(response)); + const list = $('.style_2 .Simple_title') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a').first(); + return { + title: a.text(), + link: `${baseUrl}${a.attr('href')}`, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link, { + responseType: 'buffer', + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(gbk2utf8(response)); + item.description = $('.artmainl .articlemain').first().html(); + item.pubDate = timezone(parseDate($('.artmainl .info').text().split('|')[2].split(':')[1].trim()), +8); + return item; + }) + ) + ); + + ctx.state.data = { + title: '四川工商学院 - 学院新闻', + link: requestUrl, + description: '四川工商学院 - 学院新闻', + item: items, + }; +};