From 1a8e46d9eb4a52abbe21d12f1d81a2dffdfe3825 Mon Sep 17 00:00:00 2001 From: SUPER Date: Sat, 16 Jul 2022 21:30:13 +0800 Subject: [PATCH] feat(route): tju cic news, notification and forum (#10223) * feat(route): tju cic news, notification and forum * chore: update * chore: update * chore: reserve attachments in each feed --- docs/en/university.md | 12 ++++- docs/university.md | 18 +++++-- lib/v2/tju/cic/index.js | 113 +++++++++++++++++++++++++++++++++++++++ lib/v2/tju/maintainer.js | 1 + lib/v2/tju/radar.js | 20 +++++++ lib/v2/tju/router.js | 1 + 6 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 lib/v2/tju/cic/index.js diff --git a/docs/en/university.md b/docs/en/university.md index c3981b9ff..b4e6b26eb 100644 --- a/docs/en/university.md +++ b/docs/en/university.md @@ -48,12 +48,22 @@ Note: [Source website](https://gs.bjtu.edu.cn/) only provides articles in Chines ## Tianjin University +### College of Intelligence and Computing + + + +| College News | Notification | TJU Forum for CIC | +| :----------: | :----------: | :---------------: | +| news | notification | forum | + + + ### The Office of Academic Affairs | News | Notification | -| ---- | ------------ | +| :--: | :----------: | | news | notification | diff --git a/docs/university.md b/docs/university.md index 44efd31e7..d6ce639de 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2385,12 +2385,22 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ## 天津大学 -### 天津大学教务处 +### 智能与计算学部 - + -| 新闻动态 | 通知公告 | -| ---- | ------------ | +| 学部新闻 | 通知公告 | 北洋智算论坛 | +| :--: | :----------: | :----: | +| news | notification | forum | + + + +### 教务处 + + + +| 新闻动态 | 通知公告 | +| :--: | :----------: | | news | notification | diff --git a/lib/v2/tju/cic/index.js b/lib/v2/tju/cic/index.js new file mode 100644 index 000000000..a9f4141ac --- /dev/null +++ b/lib/v2/tju/cic/index.js @@ -0,0 +1,113 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const cic_base_url = 'http://cic.tju.edu.cn/'; +const repo_url = 'https://github.com/DIYgod/RSSHub/issues'; + +const pageType = (href) => { + if (!href.startsWith('http')) { + return 'in-site'; + } + const url = new URL(href); + if (url.hostname === 'cic.tju.edu.cn') { + return 'tju-cic'; + } else { + return 'unknown'; + } +}; + +module.exports = async (ctx) => { + const type = ctx.params && ctx.params.type; + let path, subtitle; + + switch (type) { + case 'news': + subtitle = '学部新闻'; + path = 'xwzx/xyxw.htm'; + break; + case 'notification': + subtitle = '通知公告'; + path = 'xwzx/tzgg.htm'; + break; + case 'forum': + subtitle = '北洋智算论坛'; + path = 'byzslt.htm'; + break; + default: + subtitle = '学部新闻'; + path = 'xwzx/xyxw.htm'; + } + let response = null; + try { + response = await got(cic_base_url + path, { + headers: { + Referer: cic_base_url, + }, + }); + } catch (e) { + // ignore error handler + // console.log(e); + } + + if (response === null) { + ctx.state.data = { + title: '天津大学智能与计算学部 - ' + subtitle, + link: cic_base_url + path, + description: '链接失效' + cic_base_url + path, + item: [ + { + title: '提示信息', + link: repo_url, + description: `

请到此处提交Issue

`, + }, + ], + }; + } else { + const $ = cheerio.load(response.data); + const list = $('.wenzi_list_ul > li') + .map((_index, item) => { + const href = $('a', item).attr('href'); + const type = pageType(href); + return { + title: $('a', item).text(), + link: type === 'in-site' ? cic_base_url + href : href, + type, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => { + switch (item.type) { + case 'tju-cic': + case 'in-site': + return ctx.cache.tryGet(item.link, async () => { + let detailResponse = null; + try { + detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + item.pubDate = timezone(parseDate(content('.news_info > span').first().text(), 'YYYY年MM月DD日 HH:mm'), +8); + content('.news_tit').remove(); + content('.news_info').remove(); + item.description = content('.con_news_body > div').html(); + } catch (e) { + // ignore error handler + } + return item; + }); + default: + return item; + } + }) + ); + + ctx.state.data = { + title: '天津大学智能与计算学部 - ' + subtitle, + link: cic_base_url + path, + description: null, + item: items, + }; + } +}; diff --git a/lib/v2/tju/maintainer.js b/lib/v2/tju/maintainer.js index fedd83619..be49cf4bb 100644 --- a/lib/v2/tju/maintainer.js +++ b/lib/v2/tju/maintainer.js @@ -1,3 +1,4 @@ module.exports = { + '/cic/:type?': ['SuperPung'], '/oaa/:type?': ['AmosChenYQ', 'SuperPung'], }; diff --git a/lib/v2/tju/radar.js b/lib/v2/tju/radar.js index 206e59de7..26cea4082 100644 --- a/lib/v2/tju/radar.js +++ b/lib/v2/tju/radar.js @@ -1,6 +1,26 @@ module.exports = { 'tju.edu.cn': { _name: '天津大学', + cic: [ + { + title: '智能与计算学部 - 学部新闻', + docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue', + source: ['/xwzx/xyxw.htm', '/'], + target: '/tju/cic/news', + }, + { + title: '智能与计算学部 - 通知公告', + docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue', + source: ['/xwzx/tzgg.htm', '/'], + target: '/tju/cic/notification', + }, + { + title: '智能与计算学部 - 北洋智算论坛', + docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue', + source: ['/byzslt.htm', '/'], + target: '/tju/cic/forum', + }, + ], oaa: [ { title: '教务处 - 新闻动态', diff --git a/lib/v2/tju/router.js b/lib/v2/tju/router.js index 1d64b9111..f9ceec38b 100644 --- a/lib/v2/tju/router.js +++ b/lib/v2/tju/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { + router.get('/cic/:type?', require('./cic')); router.get('/oaa/:type?', require('./oaa')); };