From 4cf6fa4f3fc5cb6acb366dda0548b4b9f4989df8 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 22 Jun 2022 23:45:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=B8=AD=E5=9B=BD=E7=95=99?= =?UTF-8?q?=E5=AD=A6=E7=BD=91=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#1000?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 中国留学网通知公告 * docs: move to study --- docs/study.md | 6 +++++ lib/v2/cscse/maintainer.js | 3 +++ lib/v2/cscse/radar.js | 13 +++++++++ lib/v2/cscse/router.js | 3 +++ lib/v2/cscse/tzgg.js | 54 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 lib/v2/cscse/maintainer.js create mode 100644 lib/v2/cscse/radar.js create mode 100644 lib/v2/cscse/router.js create mode 100644 lib/v2/cscse/tzgg.js diff --git a/docs/study.md b/docs/study.md index ddafa83616..f63c6278e4 100644 --- a/docs/study.md +++ b/docs/study.md @@ -533,6 +533,12 @@ path="/ctfhub/upcoming/:limit?" +## 中国留学网 + +### 通知公告 + + + ## 中国人事考试网 ### 通知公告 diff --git a/lib/v2/cscse/maintainer.js b/lib/v2/cscse/maintainer.js new file mode 100644 index 0000000000..b6d4a7abae --- /dev/null +++ b/lib/v2/cscse/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/tzgg': ['nczitzk'], +}; diff --git a/lib/v2/cscse/radar.js b/lib/v2/cscse/radar.js new file mode 100644 index 0000000000..37042aa74f --- /dev/null +++ b/lib/v2/cscse/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cscse.edu.cn': { + _name: '中国留学网', + '.': [ + { + title: '通知公告', + docs: 'https://docs.rsshub.app/study.html#zhong-guo-liu-xue-wang-tong-zhi-gong-gao', + source: ['/cscse/index/tzgg', '/'], + target: '/cscse/tzgg', + }, + ], + }, +}; diff --git a/lib/v2/cscse/router.js b/lib/v2/cscse/router.js new file mode 100644 index 0000000000..a4b145745d --- /dev/null +++ b/lib/v2/cscse/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/tzgg', require('./tzgg')); +}; diff --git a/lib/v2/cscse/tzgg.js b/lib/v2/cscse/tzgg.js new file mode 100644 index 0000000000..7422c6fee9 --- /dev/null +++ b/lib/v2/cscse/tzgg.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.cscse.edu.cn'; + const currentUrl = `${rootUrl}/cscse/index/tzgg/index.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.news_list li a') + .toArray() + .map((item) => { + item = $(item); + + const link = item.attr('href'); + + return { + title: item.text(), + link: `${/^http/.test(link) ? '' : rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.next().text()), + }; + }); + + items = await Promise.all( + items.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('.zoom').html(); + item.author = content('meta[name="Author"]').attr('content'); + item.category = content('meta[name="Keywords"]').attr('content')?.split(','); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '中国留学网 - 通知公告', + link: currentUrl, + item: items, + }; +};