diff --git a/docs/university.md b/docs/university.md index 404db9b64ba3e3..9ae865db8a6964 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1516,6 +1516,49 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +## 湖南农业大学 + +### 教务处 + + + +| 分类 | 通知公告 | 教务动态 | 其他教务通知... | +| ---- | -------- | -------- | --------------- | +| 参数 | tzgg | jwds | 对应 URL | + + + +### 国际交流与合作处、国际教育学院、港澳台事务办公室 + + + +| 分类 | 公告通知 | 新闻快讯 | 其他分类... | +| -------- | -------- | -------- | ----------- | +| type | xwzx | xwzx | 对应 URL | +| category | tzgg | xwkx | 对应 URL | + + + +### 公共管理与法学学院 + + + +| 分类 | 通知公告 | 学院新闻 | 其他分类通知... | +| ---- | -------- | -------- | --------------- | +| 参数 | tzgg | xyxw | 对应 URL | + + + +### 信息与智能科学学院 + + + +| 分类 | 通知公告 | 学院新闻 | 其他分类通知... | +| ---- | --------- | -------- | --------------- | +| 参数 | tzgg_8472 | xyxw | 对应 URL | + + + ## 华北电力大学 ### 北京校区研究生院 diff --git a/lib/v2/hunau/gfxy/index.js b/lib/v2/hunau/gfxy/index.js new file mode 100644 index 00000000000000..75b6dc945c94d9 --- /dev/null +++ b/lib/v2/hunau/gfxy/index.js @@ -0,0 +1,11 @@ +const getContent = require('../utils/common'); + +module.exports = async (ctx) => { + await getContent(ctx, { + baseHost: 'https://gfxy.hunau.edu.cn', + baseCategory: 'tzgg', // 默认:通知公告 + baseTitle: '公共管理与法学学院', + baseDescription: '湖南农业大学公共管理与法学学院', + baseDeparment: 'gfxy', + }); +}; diff --git a/lib/v2/hunau/ied.js b/lib/v2/hunau/ied.js new file mode 100644 index 00000000000000..02be7436363ba5 --- /dev/null +++ b/lib/v2/hunau/ied.js @@ -0,0 +1,12 @@ +const getContent = require('./utils/common'); + +module.exports = async (ctx) => { + await getContent(ctx, { + baseHost: 'https://ied.hunau.edu.cn', + baseCategory: 'ggtz', // 默认:公告通知 + baseType: 'xwzx', // 默认:新闻中心 + baseTitle: '国际交流与合作处', + baseDescription: '湖南农业大学国际交流与合作处、国际教育学院、港澳台事务办公室', + baseDeparment: 'ied', + }); +}; diff --git a/lib/v2/hunau/jwc.js b/lib/v2/hunau/jwc.js new file mode 100644 index 00000000000000..c3e23585f6a07c --- /dev/null +++ b/lib/v2/hunau/jwc.js @@ -0,0 +1,10 @@ +const getContent = require('./utils/common'); + +module.exports = async (ctx) => { + await getContent(ctx, { + baseHost: 'https://jwc.hunau.edu.cn', + baseCategory: 'tzgg', // 默认:通知公告 + baseTitle: '湖南农业大学教务处', + baseDeparment: 'jwc', + }); +}; diff --git a/lib/v2/hunau/maintainer.js b/lib/v2/hunau/maintainer.js new file mode 100644 index 00000000000000..87bc67d74556c8 --- /dev/null +++ b/lib/v2/hunau/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/gfxy/:type?/:page?': ['lcandy2'], + '/ied/:type?/:category?/:page?': ['lcandy2'], + '/jwc/:type?/:page?': ['lcandy2'], + '/xky/:type?/:page?': ['lcandy2'], +}; diff --git a/lib/v2/hunau/radar.js b/lib/v2/hunau/radar.js new file mode 100644 index 00000000000000..10be3dfbab99fb --- /dev/null +++ b/lib/v2/hunau/radar.js @@ -0,0 +1,37 @@ +module.exports = { + 'hunau.edu.cn': { + _name: '湖南农业大学', + gfxy: [ + { + title: '公共管理与法学学院', + docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue', + source: ['/', 'tzgg', '/:category'], + target: '/:category', + }, + ], + ied: [ + { + title: '国际交流与合作处', + docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue', + source: ['/', '/xwzx/ggtz', '/:type/:category'], + target: '/:type/:category', + }, + ], + jwc: [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue', + source: ['/', 'tzgg', '/:category'], + target: '/:category', + }, + ], + xky: [ + { + title: '信息与智能科学技术学院', + docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue', + source: ['/', 'tzgg_8472', '/:category'], + target: '/:category', + }, + ], + }, +}; diff --git a/lib/v2/hunau/router.js b/lib/v2/hunau/router.js new file mode 100644 index 00000000000000..9369ddbda02da6 --- /dev/null +++ b/lib/v2/hunau/router.js @@ -0,0 +1,6 @@ +module.exports = (router) => { + router.get('/gfxy/:category?/:page?', require('./gfxy')); + router.get('/ied/:type?/:category?/:page?', require('./ied')); + router.get('/jwc/:category?/:page?', require('./jwc')); + router.get('/xky/:category?/:page?', require('./xky')); +}; diff --git a/lib/v2/hunau/utils/categoryTitle.js b/lib/v2/hunau/utils/categoryTitle.js new file mode 100644 index 00000000000000..c1eb2a3e1c6c5a --- /dev/null +++ b/lib/v2/hunau/utils/categoryTitle.js @@ -0,0 +1,31 @@ +const categoryTitle = (type) => { + let title; + type = type.slice(0, 4).toLowerCase(); + + switch (type) { + case 'tzgg': + title = '通知公告'; + break; + case 'ggtz': + title = '公告通知'; + break; + case 'jwdt': + title = '教务动态'; + break; + case 'xyxw': + title = '学院新闻'; + break; + case 'jzxx': + title = '讲座信息'; + break; + case 'xzzq': + title = '下载专区'; + break; + default: + title = ''; + } + + return title; +}; + +module.exports = categoryTitle; diff --git a/lib/v2/hunau/utils/common.js b/lib/v2/hunau/utils/common.js new file mode 100644 index 00000000000000..437682139bc63d --- /dev/null +++ b/lib/v2/hunau/utils/common.js @@ -0,0 +1,61 @@ +// common.js +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const categoryTitle = require('./categoryTitle'); +const newsContent = require('./newsContent'); +const indexPage = require('./indexPage'); + +async function getContent(ctx, { baseHost, baseCategory, baseType, baseTitle, baseDescription = '', baseDeparment = '', baseClass = 'div.article_list ul li:has(a)' }) { + const { category = baseCategory, type = baseType, page = '1' } = ctx.params; + + const title = `${baseTitle} - ${categoryTitle(category)}`; + const description = baseDescription ? `${baseDescription} - ${categoryTitle(category)}` : title; + + const typeURL = type ? `/${type}` : ''; + const baseURl = `${baseHost}${typeURL}/${category}`; + const url = `${baseURl}/${indexPage(page)}`; + + const { data: response } = await got(url); + const $ = cheerio.load(response); + + const list = $(baseClass) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a'); + const href = a.attr('href'); + const title = a.text(); + const link = href.startsWith('./') && !href.endsWith('.pdf') ? `${baseURl}${href.replace('./', '/')}` : href; + + return { + title, + link, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const content = await newsContent(item.link, baseDeparment); + + item.pubDate = content.pubDate; + item.description = content.description; + + return item; + }) + ) + ); + + ctx.state.data = { + // 源标题 + title, + description, + // 源链接 + link: url, + // 源文章 + item: items, + }; +} + +module.exports = getContent; diff --git a/lib/v2/hunau/utils/indexPage.js b/lib/v2/hunau/utils/indexPage.js new file mode 100644 index 00000000000000..cf86a8d47a0ef4 --- /dev/null +++ b/lib/v2/hunau/utils/indexPage.js @@ -0,0 +1,10 @@ +const indexPage = (page) => { + const fileName = 'index'; + const fileType = 'html'; + + const filePage = page === '1' ? '' : `_${parseInt(page) - 1}`; + + return `${fileName}${filePage}.${fileType}`; +}; + +module.exports = indexPage; diff --git a/lib/v2/hunau/utils/newsContent.js b/lib/v2/hunau/utils/newsContent.js new file mode 100644 index 00000000000000..181df1f7a3b699 --- /dev/null +++ b/lib/v2/hunau/utils/newsContent.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const cheerio = require('cheerio'); + +async function newsContent(link, department = '') { + try { + // 异步请求文章 + const { data: response } = await got(link, { + https: { + rejectUnauthorized: false, + }, + }); + // 加载文章内容 + const $ = cheerio.load(response); + let reg = /\d{4}\/\d{2}\/\d{2}/; + let element = '.newscontent'; + + // 处理特定部门 + if (department === 'xky') { + reg = /\d{4}-\d{2}-\d{2}/; + element = '.content .edit'; + } + + // 解析日期 + const extractDate = ($('.info').first().html()?.match(reg) || [])[0]; + const pubDate = timezone(parseDate(extractDate, 'YYYY-MM-DD', 'zh-cn'), +8); + // 解析文章 + const newsContent = $(element).first(); + newsContent.find('table').remove(); + let description = newsContent.text().replace(/\s+/g, ''); + + // 处理特定部门 + if (department === 'gfxy') { + description = description.replace('点击下载文件:', ''); + } + + // 返回解析的结果 + return { description, pubDate }; + } catch (error) { + // Handle the error (e.g., log it and return some default values) + // console.error(`There was an error fetching the link ${link}: ${error.message}`); + return { description: '', pubDate: null }; + } +} + +module.exports = newsContent; diff --git a/lib/v2/hunau/xky/index.js b/lib/v2/hunau/xky/index.js new file mode 100644 index 00000000000000..d894546312aced --- /dev/null +++ b/lib/v2/hunau/xky/index.js @@ -0,0 +1,12 @@ +const getContent = require('../utils/common'); + +module.exports = async (ctx) => { + await getContent(ctx, { + baseHost: 'https://xky.hunau.edu.cn', + baseCategory: 'tzgg_8472', // 默认:通知公告 + baseTitle: '信息与智能科学技术学院', + baseDescription: '湖南农业大学信息与智能科学技术学院', + baseDeparment: 'xky', + baseClass: 'div.right_list ul li:has(a)', + }); +};