From dd430d1ab91872a9edeca2256210b4e7d95beae3 Mon Sep 17 00:00:00 2001 From: Ishirai Date: Sat, 26 Feb 2022 23:04:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=B8=9C=E5=8D=8E=E5=A4=A7?= =?UTF-8?q?=E5=AD=A6=20=E6=95=99=E5=8A=A1=E5=A4=84-=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=85=AC=E5=91=8A=20and=20=E4=BF=A1=E6=81=AF=E5=85=AC=E5=BC=80?= =?UTF-8?q?=E7=BD=91-=E6=9C=80=E6=96=B0=E5=85=AC=E5=BC=80=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20(#8698)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 东华大学教务处-通知公告 * Update doc * Upgrade to v2 standard * Deleted v1 standard version * Add route /dhu/xxgk/news * Deleted unused param type * close tag in Line 674 * ->String(base_url) * fix lint * fix: replace depreciated url.resolve, use parseDate --- docs/university.md | 16 ++++++++++++++++ lib/v2/dhu/jiaowu/news.js | 37 +++++++++++++++++++++++++++++++++++++ lib/v2/dhu/maintainer.js | 4 ++++ lib/v2/dhu/radar.js | 17 +++++++++++++++++ lib/v2/dhu/router.js | 4 ++++ lib/v2/dhu/xxgk/news.js | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 lib/v2/dhu/jiaowu/news.js create mode 100644 lib/v2/dhu/maintainer.js create mode 100644 lib/v2/dhu/radar.js create mode 100644 lib/v2/dhu/router.js create mode 100644 lib/v2/dhu/xxgk/news.js diff --git a/docs/university.md b/docs/university.md index 0318f11805..6131708a42 100644 --- a/docs/university.md +++ b/docs/university.md @@ -683,6 +683,22 @@ xskb1 对应 +## 东华大学 + +### 教务处通知 + + + +| 学生专栏 | 教师专栏 | +| ------- | ------- | +| student | teacher | + + + +### 最新信息公开 + + + ## 东南大学 ### 信息科学与工程学院学术活动 diff --git a/lib/v2/dhu/jiaowu/news.js b/lib/v2/dhu/jiaowu/news.js new file mode 100644 index 0000000000..ab2d96590e --- /dev/null +++ b/lib/v2/dhu/jiaowu/news.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const iconv = require('iconv-lite'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const base_url = 'https://jw.dhu.edu.cn'; + +const map = { + student: '/tzggwxszl/list.htm', + teacher: '/tzggwjszl/list.htm', +}; +module.exports = async (ctx) => { + const type = ctx.params.type; + const link = map.hasOwnProperty(type) ? `${base_url}${map[type]}` : `${base_url}/tzggwxszl/list.htm`; + const response = await got({ + method: 'get', + url: link, + responseType: 'buffer', + headers: { + Referer: base_url, + }, + }); + + const $ = cheerio.load(iconv.decode(response.data, 'utf-8')); + ctx.state.data = { + link: base_url, + title: '东华大学教务处-' + $('.col_title').text(), + item: $('.list_item') + .map((_, elem) => ({ + link: new URL($('a', elem).attr('href'), base_url), + title: $('a', elem).attr('title'), + pubDate: timezone(parseDate($('.Article_PublishDate', elem).text()), +8), + })) + .get(), + }; +}; diff --git a/lib/v2/dhu/maintainer.js b/lib/v2/dhu/maintainer.js new file mode 100644 index 0000000000..4993d1b370 --- /dev/null +++ b/lib/v2/dhu/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/jiaowu/news/:type?': ['KiraKiseki'], + '/xxgk/news': ['KiraKiseki'], +}; diff --git a/lib/v2/dhu/radar.js b/lib/v2/dhu/radar.js new file mode 100644 index 0000000000..a99cdd9ccd --- /dev/null +++ b/lib/v2/dhu/radar.js @@ -0,0 +1,17 @@ +module.exports = { + 'dhu.edu.cn': { + _name: '东华大学', + jw: [ + { + title: '教务处通知', + docs: 'https://docs.rsshub.app/university.html#dong-hua-da-xue', + }, + ], + xxgk: [ + { + title: '最新信息公开', + docs: 'https://docs.rsshub.app/university.html#dong-hua-da-xue', + }, + ], + }, +}; diff --git a/lib/v2/dhu/router.js b/lib/v2/dhu/router.js new file mode 100644 index 0000000000..11dfa6b54d --- /dev/null +++ b/lib/v2/dhu/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/jiaowu/news/:type?', require('./jiaowu/news')); + router.get('/xxgk/news', require('./xxgk/news')); +}; diff --git a/lib/v2/dhu/xxgk/news.js b/lib/v2/dhu/xxgk/news.js new file mode 100644 index 0000000000..a83b85729d --- /dev/null +++ b/lib/v2/dhu/xxgk/news.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); +const iconv = require('iconv-lite'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const base_url = 'https://xxgk.dhu.edu.cn/1737/list.htm'; + +module.exports = async (ctx) => { + const link = base_url; + const response = await got({ + method: 'get', + url: link, + responseType: 'buffer', + headers: { + Referer: base_url, + }, + }); + + const $ = cheerio.load(iconv.decode(response.data, 'utf-8')); + ctx.state.data = { + link: base_url, + title: '东华大学信息公开网-最新公开信息', + item: $('.cols') + .map((_, elem) => ({ + link: new URL($('a', elem).attr('href'), base_url), + title: $('a', elem).attr('title'), + pubDate: timezone(parseDate($('.cols_meta', elem).text()), +8), + })) + .get(), + }; +};