From 50c71cd23f2e98ddc77d451311dd6ec2ac1a480a Mon Sep 17 00:00:00 2001 From: nyaShine <127018961+nyaShine@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:34:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20/lsnu/jiaowc/tzgg/:category=3F=20?= =?UTF-8?q?=E4=B9=90=E5=B1=B1=E5=B8=88=E8=8C=83=E5=AD=A6=E9=99=A2=E6=95=99?= =?UTF-8?q?=E5=AD=A6=E9=83=A8=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/lsnu/jiaowc/tzgg.js | 39 +++++++++++++++---------------- lib/v2/lsnu/radar.js | 8 +++---- lib/v2/lsnu/router.js | 2 +- website/docs/routes/university.md | 10 +++++++- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/v2/lsnu/jiaowc/tzgg.js b/lib/v2/lsnu/jiaowc/tzgg.js index 5589bb97a6..c22c16421f 100644 --- a/lib/v2/lsnu/jiaowc/tzgg.js +++ b/lib/v2/lsnu/jiaowc/tzgg.js @@ -2,9 +2,12 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { + const category = ctx.params.category; + const url = category ? `http://jiaowc.lsnu.edu.cn/tzgg/${category}.htm` : 'http://jiaowc.lsnu.edu.cn/tzgg.htm'; + const response = await got({ method: 'get', - url: 'http://jiaowc.lsnu.edu.cn/tzgg.htm', + url, }); const data = response.data; @@ -19,28 +22,24 @@ module.exports = async (ctx) => { const link = 'http://jiaowc.lsnu.edu.cn/' + $('a').attr('href'); const date = $('td[width="80"]').text(); - const cache = await ctx.cache.get(link); - if (cache) { - return JSON.parse(cache); - } + const single = await ctx.cache.tryGet(link, async () => { + const response = await got({ + method: 'get', + url: link, + }); - const response = await got({ - method: 'get', - url: link, + const articleData = response.data; + const article$ = cheerio.load(articleData); + const description = article$('.v_news_content').html(); + + return { + title, + link, + description, + pubDate: new Date(date).toUTCString(), + }; }); - const articleData = response.data; - const article$ = cheerio.load(articleData); - const description = article$('.v_news_content').html(); - - const single = { - title, - link, - description, - pubDate: new Date(date).toUTCString(), - }; - - ctx.cache.set(link, JSON.stringify(single)); return Promise.resolve(single); }) ); diff --git a/lib/v2/lsnu/radar.js b/lib/v2/lsnu/radar.js index 44a74a42b4..f028fb3495 100644 --- a/lib/v2/lsnu/radar.js +++ b/lib/v2/lsnu/radar.js @@ -1,10 +1,10 @@ module.exports = { - 'jiaowc.lsnu.edu.cn': { - _name: '乐山师范学院教学部', + 'lsnu.edu.cn': { + _name: '乐山师范学院', '.': [ { - title: '通知公告', - docs: 'https://docs.rsshub.app/', + title: '教学部通知公告', + docs: 'https://docs.rsshub.app/university.html#le-shan-shi-fan-xue-yuan', source: ['/'], target: '/lsnu/jiaowc/tzgg', }, diff --git a/lib/v2/lsnu/router.js b/lib/v2/lsnu/router.js index d2f953bf1e..1dbd6b5620 100644 --- a/lib/v2/lsnu/router.js +++ b/lib/v2/lsnu/router.js @@ -1,3 +1,3 @@ module.exports = (router) => { - router.get('/jiaowc/tzgg', require('./jiaowc/tzgg')); + router.get('/jiaowc/tzgg/:category?', require('./jiaowc/tzgg')); }; diff --git a/website/docs/routes/university.md b/website/docs/routes/university.md index 486687a0be..8e09e834c3 100644 --- a/website/docs/routes/university.md +++ b/website/docs/routes/university.md @@ -2013,7 +2013,15 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 教学部通知公告 {#le-shan-shi-fan-xue-yuan-jiao-xue-bu-tong-zhi-gong-gao} - + + +category 列表: + +| 实践教学科 | 教育运行科 | 教研教改科 | 学籍管理科 | 考试科 | 教材建设管理科 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| sjjxk | jxyxk | jyjgk | xjglk | ksk | jcjsglk | + + ## 辽宁工程技术大学 {#liao-ning-gong-cheng-ji-shu-da-xue}