diff --git a/docs/university.md b/docs/university.md index d89eca7ad..fab943a01 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2346,11 +2346,21 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 新闻网与学院通知 - + -| 新闻网 | 能源与机械工程学院 | 环境与化学工程学院 | 电气工程学院 | 自动化工程学院 | 计算机科学与技术学院 | 电子与信息学院 | 经济与管理学院 | 数理学院 | 外国语学院 | 国际交流学院 | 继续教育学院 | 马克思主义学院 | 体育部 | 艺术教育中心 | -| ---- | --------- | --------- | ------ | ------- | ---------- | ------- | ------- | ---- | ----- | ------ | ------ | ------- | --- | ------ | -| news | energy | hhxy | dqxy | zdhxy | jsjxy | dxxy | jgxy | slxy | wgyxy | gjxy | jjxy | skb | tyb | yjzx | +类型名称与默认 ID: + +| 新闻网 | 信息公开网 | 教务处 | 研究生院 / 研工部 | 党委教师工作部、人事处 | 科研处 | 国际交流与合作处(港澳台办公室) | 本科招生网 | +| ------ | ------ | --- | ---------- | ----------- | --- | ---------------- | ----- | +| news | xxgk | jwc | yjsc | rsc | kyc | fao | zs | +| notice | zxgkxx | 227 | 1161 | 1695 | 834 | tzgg | zxxx | + +| 能源与机械工程学院 | 环境与化学工程学院 | 电气工程学院 | 自动化工程学院 | 计算机科学与技术学院 | 电子与信息工程学院 | 经济与管理学院 | 数理学院 | 外国语学院 | 继续教育学院 | 马克思主义学院 | 体育学院 | +| --------- | --------- | ------ | ------- | ---------- | --------- | ------- | ---- | ----- | ------ | ------- | ---- | +| energy | hhxy | dqxy | zdhxy | jsjxy | dxxy | jgxy | slxy | wgyxy | jjxy | skb | tyb | +| 892 | 1231 | 2462 | 2002 | 973 | tzgg | 3633 | 2063 | tzgg | 2582 | 1736 | 2891 | + +参数与来源页面对应规则为:`https://${type}.shiep.edu.cn/${id}/list.htm` diff --git a/lib/router.js b/lib/router.js index 616c2d9f4..d2f4bb6b6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3095,8 +3095,8 @@ router.get('/3k8/latest', lazyloadRouteHandler('./routes/3k8/latest')); // JustRun router.get('/justrun', lazyloadRouteHandler('./routes/justrun/index')); -// 上海电力大学 -router.get('/shiep/:type', lazyloadRouteHandler('./routes/universities/shiep/index')); +// 上海电力大学 migrated to v2 +// router.get('/shiep/:type/:id?', lazyloadRouteHandler('./routes/universities/shiep/index')); // 福建新闻 router.get('/fjnews/:city/:limit', lazyloadRouteHandler('./routes/fjnews/fznews')); diff --git a/lib/routes/universities/shiep/index.js b/lib/routes/universities/shiep/index.js deleted file mode 100644 index ce2bb9bac..000000000 --- a/lib/routes/universities/shiep/index.js +++ /dev/null @@ -1,95 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const type = ctx.params.type; - - const config = { - news: { - title: '新闻网', - url: 'notice', - }, - energy: { - title: '能机学院', - url: '894', - }, - hhxy: { - title: '环化学院', - url: '1231', - }, - dqxy: { - title: '电气学院', - url: '2462', - }, - zdhxy: { - title: '自动化学院', - url: '2002', - }, - jsjxy: { - title: '计算机学院', - url: '973', - }, - dxxy: { - title: '电信学院', - url: '3404', - }, - jgxy: { - title: '经管学院', - url: '3633', - }, - slxy: { - title: '数理学院', - url: '2063', - }, - wgyxy: { - title: '外国语学院', - url: 'tzgg', - }, - gjjlxy: { - title: '国交学院', - url: 'tzgg', - }, - jjxy: { - title: '继续教育学院', - url: '2582', - }, - skb: { - title: '马院', - url: '1736', - }, - tyb: { - title: '体育部', - url: '2891', - }, - yjzx: { - title: '艺教中心', - url: '3089', - }, - }; - - const link = config[type].url; - - const { data } = await got({ - method: 'get', - url: `https://${type}.shiep.edu.cn/${link}/list.htm`, - }); - - const $ = cheerio.load(data); - const list = $('div[class="fields pr_fields"]'); - - ctx.state.data = { - title: '上海电力大学-' + config[type].title, - link: `https://${type}.shiep.edu.cn/${link}/list.htm`, - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('a').text(), - link: item.find('a').attr('href'), - }; - }) - .get(), - }; -}; diff --git a/lib/v2/shiep/index.js b/lib/v2/shiep/index.js new file mode 100644 index 000000000..0d3d28971 --- /dev/null +++ b/lib/v2/shiep/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + const config = { + dqxy: { title: '电气工程学院', id: '2462' }, + dxxy: { title: '电子与信息工程学院', id: 'tzgg' }, + energy: { title: '能源与机械工程学院', id: '892' }, + fao: { title: '国际交流与合作处(港澳台办公室)', id: 'tzgg' }, + gjjlxy: { title: '国际交流学院', id: 'tzgg' }, // NAME_NOT_RESOLVED + hhxy: { title: '环境与化学工程学院', id: '1231' }, + jgxy: { title: '经济与管理学院', id: '3633' }, + jjxy: { title: '继续教育学院', id: '2582' }, + jsjxy: { title: '计算机科学与技术学院', id: '973' }, + jwc: { title: '教务处', id: '227' }, + kyc: { title: '科研处', id: '834' }, + news: { title: '新闻网', id: 'notice' }, + rsc: { title: '党委教师工作部、人事处', id: '1695' }, + skb: { title: '马克思主义学院', id: '1736' }, + slxy: { title: '数理学院', id: '2063' }, + tyb: { title: '体育学院', id: '2891' }, + wgyxy: { title: '外国语学院', id: 'tzgg' }, + xxgk: { title: '信息公开网', id: 'zxgkxx' }, + yjsc: { title: '研究生院/研工部', id: '1161' }, + yjzx: { title: '人文艺术学院', id: '3089' }, // NAME_NOT_RESOLVED + zdhxy: { title: '自动化工程学院', id: '2002' }, + zs: { title: '本科招生网', id: 'zxxx' }, + }; + + if (!Object.keys(config).includes(type)) { + throw Error('Invalid type'); + } + + const id = ctx.params.id ?? config[type].id; + + const response = await got({ + method: 'get', + url: `https://${type}.shiep.edu.cn/${id}/list.htm`, + }); + const data = response.data; + const $ = cheerio.load(data); + const class_name = 'list_item'; + const pubDateClass = type === 'dxxy' ? 'div[class="article-publishdate"]' : 'span[class="Article_PublishDate"]'; // 适配电子与信息工程学院网站改版 + const list = $(`.${class_name}`); + + ctx.state.data = { + title: '上海电力大学-' + config[type].title, + link: `https://${type}.shiep.edu.cn/${id}/list.htm`, + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('a').text(), + link: item.find('a').attr('href'), + pubDate: parseDate(item.find(pubDateClass).text().trim(), 'YYYY-MM-DD'), + }; + }) + .get(), + }; +}; diff --git a/lib/v2/shiep/maintainer.js b/lib/v2/shiep/maintainer.js new file mode 100644 index 000000000..f77951dcb --- /dev/null +++ b/lib/v2/shiep/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type/:id?': ['gumibea', 'TeamSUEP'], +}; diff --git a/lib/v2/shiep/radar.js b/lib/v2/shiep/radar.js new file mode 100644 index 000000000..67ef43424 --- /dev/null +++ b/lib/v2/shiep/radar.js @@ -0,0 +1,181 @@ +module.exports = { + 'shiep.edu.cn': { + _name: '上海电力大学', + dqxy: [ + { + title: '电气工程学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/dqxy/:id', + }, + ], + dxxy: [ + { + title: '电子信息工程学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/dxxy/:id', + }, + ], + energy: [ + { + title: '能源与机械工程学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/energy/:id', + }, + ], + fao: [ + { + title: '国际交流与合作处(港澳台办公室)', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/fao/:id', + }, + ], + gjjlxy: [ + { + title: '国际交流学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/gjjlxy/:id', + }, + ], + hhxy: [ + { + title: '环境与化学工程学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/hhxy/:id', + }, + ], + jgxy: [ + { + title: '经济与管理学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/jgxy/:id', + }, + ], + jjxy: [ + { + title: '继续教育学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/jjxy/:id', + }, + ], + jsjxy: [ + { + title: '计算机科学与技术学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/jsjxy/:id', + }, + ], + jwc: [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/jwc/:id', + }, + ], + kyc: [ + { + title: '科研处', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/kyc/:id', + }, + ], + news: [ + { + title: '新闻网', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/news/:id', + }, + ], + rsc: [ + { + title: '党委教师工作部、人事处', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/rsc/:id', + }, + ], + skb: [ + { + title: '马克思主义学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/skb/:id', + }, + ], + slxy: [ + { + title: '数理学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/slxy/:id', + }, + ], + tyb: [ + { + title: '体育学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/tyb/:id', + }, + ], + wgyxy: [ + { + title: '外国语学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/wgyxy/:id', + }, + ], + xxgk: [ + { + title: '信息公开网', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/xxgk/:id', + }, + ], + yjsc: [ + { + title: '研究生院/研工部', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/yjsc/:id', + }, + ], + yjzx: [ + { + title: '人文艺术学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/yjzx/:id', + }, + ], + zdhxy: [ + { + title: '自动化工程学院', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/zdhxy/:id', + }, + ], + zs: [ + { + title: '本科招生网', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:id/list.htm'], + target: '/shiep/zs/:id', + }, + ], + }, +}; diff --git a/lib/v2/shiep/router.js b/lib/v2/shiep/router.js new file mode 100644 index 000000000..320171958 --- /dev/null +++ b/lib/v2/shiep/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:type/:id?', require('./index')); +};