From ff1cc11929693283b2c596a19b63498a6b2f0758 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 17:08:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=9B=9B=E5=B7=9D?= =?UTF-8?q?=E5=86=9C=E4=B8=9A=E5=A4=A7=E5=AD=A6=E6=8B=9B=E7=94=9F=E5=B0=B1?= =?UTF-8?q?=E4=B8=9A=20(#8557)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 12 +++++++++ lib/v2/sicau/maintainer.js | 3 +++ lib/v2/sicau/radar.js | 13 ++++++++++ lib/v2/sicau/router.js | 3 +++ lib/v2/sicau/zsjy.js | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 lib/v2/sicau/maintainer.js create mode 100644 lib/v2/sicau/radar.js create mode 100644 lib/v2/sicau/router.js create mode 100644 lib/v2/sicau/zsjy.js diff --git a/docs/university.md b/docs/university.md index b1e3aa2da..6a7fdb39a 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1905,6 +1905,18 @@ type 列表: +## 四川农业大学 + +### 招生就业 + + + +| 本科生招生 | 研究生招生 | 毕业生选录指南 | +| ---------- | ---------- | -------------- | +| bkszs | yjszs | bysxlzn | + + + ## 四川职业技术学院 ### 学院公告 diff --git a/lib/v2/sicau/maintainer.js b/lib/v2/sicau/maintainer.js new file mode 100644 index 000000000..22afa8389 --- /dev/null +++ b/lib/v2/sicau/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/zsjy/:category?': ['nczitzk'], +}; diff --git a/lib/v2/sicau/radar.js b/lib/v2/sicau/radar.js new file mode 100644 index 000000000..77868cb6b --- /dev/null +++ b/lib/v2/sicau/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sicau.edu.cn': { + _name: '', + dky: [ + { + title: '招生就业', + docs: 'https://docs.rsshub.app/university.html#si-chuan-nong-ye-da-xue-zhao-sheng-jiu-ye', + source: ['/'], + target: '/sicau/zsjy/:category?', + }, + ], + }, +}; diff --git a/lib/v2/sicau/router.js b/lib/v2/sicau/router.js new file mode 100644 index 000000000..da91a6da2 --- /dev/null +++ b/lib/v2/sicau/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/zsjy/:category?', require('./zsjy')); +}; diff --git a/lib/v2/sicau/zsjy.js b/lib/v2/sicau/zsjy.js new file mode 100644 index 000000000..e45fb42ab --- /dev/null +++ b/lib/v2/sicau/zsjy.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'bkszs'; + + const rootUrl = 'https://dky.sicau.edu.cn'; + const currentUrl = `${rootUrl}/zsjy/${category}.htm`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('a.tit') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + pubDate: parseDate(item.prev().text()), + link: `${rootUrl}${item.attr('href').replace(/\.\./, '/')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.v_news_content p').slice(0, 2).remove(); + + item.description = content('.v_news_content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};