From 09f1c58e8f46a163d9c7c01a9dbfe2bb7693bb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BA=E5=85=B0=E6=98=9F=E8=BE=B0?= Date: Tue, 31 Jan 2023 22:24:30 +0800 Subject: [PATCH] feat(route): add support for XAUFE jiaowu route (#11740) * feat(route): XAUFE jiaowu * feat(route): support radar for XAUFE route * fix: Incomplete string escaping or encoding * Apply suggestions from code review Co-authored-by: Tony * fix: excessive slice --------- Co-authored-by: Tony --- docs/university.md | 12 +++++++ lib/v2/xaufe/jiaowu.js | 72 ++++++++++++++++++++++++++++++++++++++ lib/v2/xaufe/maintainer.js | 3 ++ lib/v2/xaufe/radar.js | 11 ++++++ lib/v2/xaufe/router.js | 3 ++ 5 files changed, 101 insertions(+) create mode 100644 lib/v2/xaufe/jiaowu.js create mode 100644 lib/v2/xaufe/maintainer.js create mode 100644 lib/v2/xaufe/radar.js create mode 100644 lib/v2/xaufe/router.js diff --git a/docs/university.md b/docs/university.md index d61a68db42..bc55b382ed 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2983,6 +2983,18 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +## 西安财经大学 + +### 教务处 + + + +| 通知公告 | +| :--: | +| tzgg | + + + ## 西南财经大学 ### 经济信息工程学院 diff --git a/lib/v2/xaufe/jiaowu.js b/lib/v2/xaufe/jiaowu.js new file mode 100644 index 0000000000..0d7eddc1ba --- /dev/null +++ b/lib/v2/xaufe/jiaowu.js @@ -0,0 +1,72 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +// Yep http is bad, but I had no choice :( +const rootMeta = { + url: 'http://jiaowu.xaufe.edu.cn/', + title: '西安财经大学 教务处(招生办公室)', +}; + +const categories = { + tzgg: { + title: '通知公告', + url: 'index/tzgg.htm', + }, +}; + +module.exports = async (ctx) => { + const pCategory = ctx.params.category; + const category = categories[pCategory] || categories.tzgg; + + const response = ( + await got({ + method: 'get', + url: rootMeta.url + category.url, + }) + ).body; + + const $ = cheerio.load(response); + + const data = $('.main_conRCb ul li') + .slice(0, 16) + .toArray() + .map((item) => { + item = $(item); + const pubDate = item.children('span').text(); + const title = item.find('a em').text(); + const link = item + .children('a') + .attr('href') + .replace(/\.\.\//g, rootMeta.url); + return { + pubDate: parseDate(pubDate), + title, + link, + }; + }); + + ctx.state.data = { + title: `${category.title}-${rootMeta.title}`, + link: rootMeta.url + category.url, + description: `${category.title}-${rootMeta.title}`, + language: 'zh_CN', + item: await Promise.all( + data.map((item) => + ctx.cache.tryGet(item.link, async () => { + const $ = cheerio.load( + ( + await got({ + method: 'get', + url: item.link, + }) + ).body + ); + item.author = /作者:(\S*)\s{4}/g.exec($('p', '.main_contit').text())[1]; + item.description = $('#vsb_content').html(); + return item; + }) + ) + ), + }; +}; diff --git a/lib/v2/xaufe/maintainer.js b/lib/v2/xaufe/maintainer.js new file mode 100644 index 0000000000..ca91495cc5 --- /dev/null +++ b/lib/v2/xaufe/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/jiaowu/:category?': ['shaokeyibb'], +}; diff --git a/lib/v2/xaufe/radar.js b/lib/v2/xaufe/radar.js new file mode 100644 index 0000000000..bfce6b3905 --- /dev/null +++ b/lib/v2/xaufe/radar.js @@ -0,0 +1,11 @@ +module.exports = { + 'xaufe.edu.cn': { + _name: '西安财经大学', + jiaowu: [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/university.html#xi-an-cai-jing-da-xue', + }, + ] + }, +}; diff --git a/lib/v2/xaufe/router.js b/lib/v2/xaufe/router.js new file mode 100644 index 0000000000..722070bca2 --- /dev/null +++ b/lib/v2/xaufe/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/jiaowu/:category?', require('./jiaowu')); +};