From fd18a0e9d102b92080b7b0df2aa5b9a1e856758e Mon Sep 17 00:00:00 2001 From: GalaxvSpaceship Date: Sun, 25 Feb 2024 07:49:47 +0800 Subject: [PATCH] feat(route): Add routes to SISU news. (#14546) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): Add route to SISU news ```routes /shisu/news ``` ## New RSS Route Checklist / 新 RSS 路由检查表 - [x] New Route / 新的路由 - [x] Follows [v2 Script Standard](https://docs.rsshub.app/joinus/advanced/script-standard) / 跟随 [v2 路由规范](https://docs.rsshub.app/zh/joinus/advanced/script-standard) - [ ] Documentation / 文档说明 - [x] Full text / 全文获取 - [x] Use cache / 使用缓存 - [ ] Anti-bot or rate limit / 反爬/频率限制 - [ ] If yes, do your code reflect this sign? / 如果有, 是否有对应的措施? - [x] [Date and time](https://docs.rsshub.app/joinus/advanced/pub-date) / [日期和时间](https://docs.rsshub.app/zh/joinus/advanced/pub-date) - [x] Parsed / 可以解析 - [x] Correct time zone / 时区正确 - [ ] New package added / 添加了新的包 - [ ] `Puppeteer` * Update university.mdx * Update news.js * Update news.js Modified the url... * fix(route): Add more options to SISU news. ```route /shisu/news /shisu/news/notice /shisu/news/campus ``` * fix: some small problems. * feat(route): Add more options to SISU news. ```routes /shisu/news /shisu/news/notice /shisu/news/campus ``` * fix(routes): modified to the correct route. * Forgot to format the document. * fix(route): made category mandatory * Update news.js --- lib/v2/shisu/maintainer.js | 3 ++ lib/v2/shisu/news.js | 63 ++++++++++++++++++++++++++++++ lib/v2/shisu/radar.js | 13 ++++++ lib/v2/shisu/router.js | 3 ++ website/docs/routes/university.mdx | 10 +++++ 5 files changed, 92 insertions(+) create mode 100644 lib/v2/shisu/maintainer.js create mode 100644 lib/v2/shisu/news.js create mode 100644 lib/v2/shisu/radar.js create mode 100644 lib/v2/shisu/router.js diff --git a/lib/v2/shisu/maintainer.js b/lib/v2/shisu/maintainer.js new file mode 100644 index 000000000..6c1396234 --- /dev/null +++ b/lib/v2/shisu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category': ['Duuckjing'], +}; diff --git a/lib/v2/shisu/news.js b/lib/v2/shisu/news.js new file mode 100644 index 000000000..6544eb930 --- /dev/null +++ b/lib/v2/shisu/news.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const url = 'https://news.shisu.edu.cn'; +const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png'; + +module.exports = async (ctx) => { + const { section = 'news' } = ctx.params; + const { data: r } = await got(`${url}/${section}/index.html`); + const $ = cheerio.load(r); + let itemsoup; + switch (section) { + case 'news': + itemsoup = $('#gallery-wrapper > article') + .toArray() + .map((i0) => { + const i = $(i0); + const img = i.find('img').attr('src'); + return { + title: i.find('a').text().trim(), + link: `${url}${i.find('a').attr('href')}`, + category: i.find('.in-con02 > span:nth-child(1)').text(), + itunes_item_image: `${url}${img}` + }; + }); + break; + default: + itemsoup = $('li.clear') + .toArray() + .map((i0) => { + const i = $(i0); + return { + title: i.find('h3>a').attr('title').trim(), + link: `${url}${i.find('h3>a').attr('href')}`, + category: i.find('p>span:nth-child(1)').text(), + }; + }); + }; + const items = await Promise.all( + itemsoup.map((j) => + ctx.cache.tryGet(j.link, async () => { + const { data: r } = await got(j.link); + const $ = cheerio.load(r); + const img = $('.tempWrap > ul > li:nth-child(1)> img').attr('src'); + j.description = $('.ot_main_r .content').html(); + j.author = $('.math_time_l > span:nth-child(3)').text().trim(); + j.pubDate = timezone(parseDate($('.math_time_l > span:nth-child(2)').text(), 'YYYY-MM-DD'), +8); + if (!j.itunes_item_image) { + j.itunes_item_image = img ? `${url}${img}` : banner; + } + return j; + })) + ); + + ctx.state.data = { + title: `上外新闻|SISU TODAY -${section.charAt(0).toUpperCase() + section.slice(1)}`, + image: 'https://bkimg.cdn.bcebos.com/pic/8d5494eef01f3a296b70affa9825bc315c607c4d?x-bce-process=image/resize,m_lfit,w_536,limit_1/quality,Q_70', + link: `${url}/${section}/index.html`, + item: items, + }; +}; diff --git a/lib/v2/shisu/radar.js b/lib/v2/shisu/radar.js new file mode 100644 index 000000000..2afb8b858 --- /dev/null +++ b/lib/v2/shisu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'shisu.edu.cn': { + _name: '上海外国语大学', + news: [ + { + title: '上外新闻', + docs: 'https://docs.rsshub.app/routes/university#shang-hai-wai-guo-yu-da-xue', + source: ['/:category/index.html'], + target: '/shisu/news/:category', + }, + ], + }, +}; diff --git a/lib/v2/shisu/router.js b/lib/v2/shisu/router.js new file mode 100644 index 000000000..37ca55cd6 --- /dev/null +++ b/lib/v2/shisu/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news/:category', require('./news')); +}; diff --git a/website/docs/routes/university.mdx b/website/docs/routes/university.mdx index 6b855591d..5df29682e 100644 --- a/website/docs/routes/university.mdx +++ b/website/docs/routes/university.mdx @@ -2625,6 +2625,16 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE\_TL | 1793 | sstmzs | +## 上海外国语大学 {#shang-hai-eai-guo-yu-da-xue} + +### 上外新闻 {#shang-hai-eai-guo-yu-da-xue-sisu-news} + + +| 首页 | 特稿 | 学术 | 教学 | 国际 | 校园 | 人物 | 视讯 | 公告 | +| ---- | -------- | -------- | -------- | ------------- | ------ | ------ | ---------- | ------ | +| news | gazette | research- | academics- | international | campus | people | multimedia | notice | + + ## 深圳大学 {#shen-zhen-da-xue} ### 研究生招生网 {#shen-zhen-da-xue-yan-jiu-sheng-zhao-sheng-wang}