diff --git a/lib/v2/jsu/cxzx.js b/lib/v2/jsu/cxzx.js new file mode 100644 index 000000000..2aad79f5a --- /dev/null +++ b/lib/v2/jsu/cxzx.js @@ -0,0 +1,75 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const { parseDate } = require('@/utils/parse-date'); +const { getPageItemAndDate } = require('./utils/index'); + +module.exports = async (ctx) => { + // 在此处编写您的逻辑 + const { types = 'xkjs' } = ctx.params; + const baseUrl = 'https://cxzx.jsu.edu.cn/'; + const urls = { + tzgg: { + url: 'https://cxzx.jsu.edu.cn/xwzx.htm', + title: '通知公告', + }, // 通知公告页面 + xkjs: { + url: 'https://cxzx.jsu.edu.cn/xwzx/zxdt.htm', + title: '学科竞赛公告', + }, + cxtz: { + url: 'https://cxzx.jsu.edu.cn/cxlt/xsjz1.htm', + title: '创新项目公告', + }, + jsxw: { + url: 'https://cxzx.jsu.edu.cn/cxjs.htm', + title: '竞赛新闻', + }, + jstz: { + url: 'https://cxzx.jsu.edu.cn/cxjs/xkjs.htm', + title: '竞赛新闻 -> 通知公告', + }, + }; + // 获取页面中所有的 body > div.cx_big_container > div.cx_content_container > div.cx_right_part > div.cx_article_list_box > table > tbody > tr + const response = await got({ + method: 'get', + url: urls[types].url, + }); + + const $ = cheerio.load(response.data); + const list = $('tr[height="20"]').toArray(); + + const out = await Promise.all( + list.map((item) => { + item = $(item); + const link = new URL(item.find('td:nth-child(2) > a').attr('href'), baseUrl).href; + return ctx.cache.tryGet(link, async () => { + const title = item.find('td:nth-child(2) > a').text() || '无标题'; + + const category = urls[types].title; + const description = await getPageItemAndDate( + '#vsb_newscontent', + link, + 'body > div.cx_big_container > div.cx_content_container > div.cx_right_part > div.viewbox > form > table > tbody > tr:nth-child(1) > td', + 'body > div.cx_big_container > div.cx_content_container > div.cx_right_part > div.viewbox > form > table > tbody > tr:nth-child(2) > td > span.timestyle134612' + ); + const pubDate = parseDate(description.date); + return { + title, + link, + pubDate, + description: description.pageInfo, + category, + }; + }); + }) + ); + + ctx.state.data = { + // 在此处输出您的 RSS + title: `吉首大学创新中心 - ${urls[types].title}`, + link: urls[types].url, + description: '吉首大学创新中心', + item: out, + }; +}; diff --git a/lib/v2/jsu/jwc.js b/lib/v2/jsu/jwc.js new file mode 100644 index 000000000..eacd448da --- /dev/null +++ b/lib/v2/jsu/jwc.js @@ -0,0 +1,59 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const { parseDate } = require('@/utils/parse-date'); +const { getPageItemAndDate } = require('@/v2/jsu/utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://jwc.jsu.edu.cn/'; + const { types = 'jwtz' } = ctx.params; + const selectors = { + jwtz: { + category: '教务通知', + url: 'https://jwc.jsu.edu.cn/tzgg.htm', + }, + jwdt: { + category: '教务动态', + url: 'https://jwc.jsu.edu.cn/jwdt.htm', + }, + }; + const response = await got({ + method: 'get', + url: selectors[types].url, + }); + + const $ = cheerio.load(response.data); + const list = $('a.c135042').toArray(); + const out = await Promise.all( + list.map((item) => { + item = $(item); + const link = new URL(item.attr('href'), baseUrl).href; + return ctx.cache.tryGet(link, async () => { + const description = await getPageItemAndDate( + '#vsb_content', + link, + 'body > div.w1180.nyWrap.clearfix > div.nyRight > div > div.passage.contPsg > form > div > h1', + 'body > div.w1180.nyWrap.clearfix > div.nyRight > div > div.passage.contPsg > form > div > div:nth-child(2)', + (date) => date.split('     文章来源:')[0].split('添加时间:')[1] + ); + const category = selectors[types].category; + const pubDate = parseDate(description.date, 'YYYY年MM月DD日'); + return { + title: description.title, + link, + pubDate, + description: description.pageInfo, + category, + }; + }); + }) + ); + + ctx.state.data = { + // 在此处输出您的 RSS + title: `吉首大学教务处 - ${selectors[types].category}`, + link: selectors[types].url, + description: `吉首大学教务处 - ${selectors[types].category}`, + item: out, + }; +}; diff --git a/lib/v2/jsu/maintainer.js b/lib/v2/jsu/maintainer.js new file mode 100644 index 000000000..b266d79da --- /dev/null +++ b/lib/v2/jsu/maintainer.js @@ -0,0 +1,7 @@ +module.exports = { + '/cxzx/:types?': ['wenjia03'], + '/jwc/:types?': ['wenjia03'], + '/notice': ['wenjia03'], + '/rjxy': ['wenjia03'], + '/stxy': ['wenjia03'], +}; diff --git a/lib/v2/jsu/math.js b/lib/v2/jsu/math.js new file mode 100644 index 000000000..72f37eadf --- /dev/null +++ b/lib/v2/jsu/math.js @@ -0,0 +1,41 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const { parseDate } = require('@/utils/parse-date'); +const { getPageItemAndDate } = require('@/v2/jsu/utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://stxy.jsu.edu.cn/'; + + const response = await got({ + method: 'get', + url: 'https://stxy.jsu.edu.cn/index/tzgg1.htm', + }); + + const $ = cheerio.load(response.data); + const list = $('div.art_list').toArray(); + const out = await Promise.all( + list.map((item) => { + item = $(item); + const link = new URL(item.find('a').attr('href'), baseUrl).href; + return ctx.cache.tryGet(link, async () => { + const description = await getPageItemAndDate('#right_con > form > div.articleInfo', link, '#right_con > form > div.articleTitle', '#right_con > form > div.articleAuthor > span:nth-child(1)'); + const pubDate = parseDate(description.date, 'YYYY年MM月DD日 HH:mm'); + return { + title: description.title, + link, + pubDate, + description: description.pageInfo, + category: '通知公告', + }; + }); + }) + ); + + ctx.state.data = { + title: '吉首大学数学与统计学院 - 通知公告', + link: 'https://stxy.jsu.edu.cn/index/tzgg1.htm', + description: '吉首大学数学与统计学院 - 通知公告', + item: out, + }; +}; diff --git a/lib/v2/jsu/radar.js b/lib/v2/jsu/radar.js new file mode 100644 index 000000000..bd4475f1e --- /dev/null +++ b/lib/v2/jsu/radar.js @@ -0,0 +1,36 @@ +module.exports = { + 'jsu.edu.cn': { + _name: '吉首大学', + '.': [ + { + title: '通知公告', + docs: 'https://docs.rsshub.app/routes/university#ji-shou-da-xue-tong-zhi-gong-gao', + }, + ], + 'cxzx': [ + { + title: '创新中心', + docs: 'https://docs.rsshub.app/routes/university#ji-shou-da-xue-chuang-xin-zhong-xin', + }, + ], + 'jwc': [ + { + title: '教务处', + docs: 'https://docs.rsshub.app/routes/university#ji-shou-da-xue-jiao-wu-chu', + }, + ], + + 'rjxy': [ + { + title: '计算机科学与工程学院', + docs: 'https://docs.rsshub.app/routes/university##ji-shou-da-xue-ji-suan-ji-ke-xue-yu-gong-cheng-xue-yuan', + }, + ], + 'stxy': [ + { + title: '数学与统计学院', + docs: 'https://docs.rsshub.app/routes/university#ji-shou-da-xue-shu-xue-yu-tong-ji-xue-yuan', + }, + ], + }, +}; diff --git a/lib/v2/jsu/rjxy.js b/lib/v2/jsu/rjxy.js new file mode 100644 index 000000000..aa5d5c71b --- /dev/null +++ b/lib/v2/jsu/rjxy.js @@ -0,0 +1,43 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const { parseDate } = require('@/utils/parse-date'); +const { getPageItemAndDate } = require('@/v2/jsu/utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://rjxy.jsu.edu.cn/'; + + const response = await got({ + method: 'get', + url: 'https://rjxy.jsu.edu.cn/index/tzgg1.htm', + }); + + const $ = cheerio.load(response.data); + const list = $('body > div.list-box > div > ul > li').toArray(); + const out = await Promise.all( + list.map((item) => { + item = $(item); + const link = new URL(item.find('a').attr('href'), baseUrl).href; + return ctx.cache.tryGet(link, async () => { + const category = '通知公告'; + const description = await getPageItemAndDate('#vsb_content', link, 'body > form > div > h1', 'body > form > div > div.label', (date) => date.split(' 点击:')[0]); + const pubDate = parseDate(description.date, 'YYYY年MM月DD日 HH:mm'); + return { + title: description.title, + link, + pubDate, + description: description.pageInfo, + category, + }; + }); + }) + ); + + ctx.state.data = { + // 在此处输出您的 RSS + title: '吉首大学计算机科学与工程学院 - 通知公告', + link: 'https://rjxy.jsu.edu.cn/index/tzgg1.htm', + description: '吉首大学计算机科学与工程学院 - 通知公告', + item: out, + }; +}; diff --git a/lib/v2/jsu/router.js b/lib/v2/jsu/router.js new file mode 100644 index 000000000..835e4ecbd --- /dev/null +++ b/lib/v2/jsu/router.js @@ -0,0 +1,8 @@ +module.exports = (router) => { + // 创新中心 + router.get('/cxzx/:types?', require('./cxzx')); + router.get('/jwc/:types?', require('./jwc')); + router.get('/notice', require('./universityindex')); + router.get('/rjxy', require('./rjxy')); + router.get('/stxy', require('./math')); +}; diff --git a/lib/v2/jsu/universityindex.js b/lib/v2/jsu/universityindex.js new file mode 100644 index 000000000..51e1b823f --- /dev/null +++ b/lib/v2/jsu/universityindex.js @@ -0,0 +1,48 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const { parseDate } = require('@/utils/parse-date'); +const { getPageItemAndDate } = require('./utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://www.jsu.edu.cn/'; + + const response = await got({ + method: 'get', + url: 'https://www.jsu.edu.cn/index/tzgg.htm', + }); + + const $ = cheerio.load(response.data); + const list = $('body > div.container.container-fluid.dynava.no-padding.cleafix > div.con_wz_fr.fr.cleafix > div:nth-child(2) > ul > li').toArray(); + const out = await Promise.all( + list.map((item) => { + item = $(item); + const link = new URL(item.find('a').attr('href'), baseUrl).href; + return ctx.cache.tryGet(link, async () => { + const description = await getPageItemAndDate( + '#vsb_content', + link, + 'body > div.container.container-fluid.dynava.no-padding.cleafix > div.con_wz_fr.fr.cleafix > form > div > h1', + 'body > div.container.container-fluid.dynava.no-padding.cleafix > div.con_wz_fr.fr.cleafix > form > div > div:nth-child(2)', + (date) => date.split('时间:')[1].split(' 作者:')[0] + ); + const pubDate = parseDate(description.date, 'YYYY-MM-DD'); + return { + title: description.title, + link, + pubDate, + description: description.pageInfo, + category: '通知公告', + }; + }); + }) + ); + + ctx.state.data = { + // 在此处输出您的 RSS + title: '吉首大学 - 通知公告', + link: 'https://www.jsu.edu.cn/index/tzgg.htm', + description: '吉首大学 - 通知公告', + item: out, + }; +}; diff --git a/lib/v2/jsu/utils/index.js b/lib/v2/jsu/utils/index.js new file mode 100644 index 000000000..1a41053d0 --- /dev/null +++ b/lib/v2/jsu/utils/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 + +/** + * 获取页面内容 + * @param selector 正文CSS选择器 + * @param pageUrl 页面URL + * @returns {Promise} 页面内容,为符合RSS规范的HTML + */ +async function getPageItem(selector, pageUrl) { + const response = await got({ + method: 'get', + url: pageUrl, + https: { rejectUnauthorized: false }, + }); + const $ = cheerio.load(response.data); + const page = $(selector); + return page ? page.html() : '无法获取内容'; +} + +/** + * 获取页面内容、标题、日期 + * @param selector 正文CSS选择器 + * @param pageUrl 页面URL + * @param titleSelector 标题CSS选择器 + * @param dateSelector 日期CSS选择器 + * @param dateHander 日期处理函数,在CMS系统中会以“日期:点击数”等特殊格式显示日期,需要处理切分出日期 + * @returns {Promise<{date, pageInfo: string, title: (*|jQuery|string)}|{date: string, pageInfo: string, title: string}>} 页面内容、标题、日期 + */ +async function getPageDetails(selector, pageUrl, titleSelector, dateSelector, dateHander = (date) => date) { + const response = await got({ + method: 'get', + url: pageUrl, + https: { rejectUnauthorized: false }, + }); + const $ = cheerio.load(response.data); + const page = $(selector); + const date = dateHander($(dateSelector).text()); + const title = $(titleSelector).text(); + return page + ? { pageInfo: page.html(), date, title } + : { + pageInfo: '无法获取内容', + date: '1970-1-1', + title: '无法获取标题', + }; +} + +module.exports = { + getPageItem, + getPageItemAndDate: getPageDetails, +}; diff --git a/website/docs/routes/university.mdx b/website/docs/routes/university.mdx index 6aae18313..316a957e4 100644 --- a/website/docs/routes/university.mdx +++ b/website/docs/routes/university.mdx @@ -3655,3 +3655,33 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE\_TL | -------- | -------- | -------- | -------- | | results | papers | writings | policy | + +## 吉首大学 {#ji-shou-da-xue} + +### 通知公告 {#ji-shou-da-xue-tong-zhi-gong-gao} + + + +### 计算机科学与工程学院 - 通知公告 {#ji-shou-da-xue-ji-suan-ji-ke-xue-yu-gong-cheng-xue-yuan} + + + +### 教务处 {#ji-shou-da-xue-jiao-wu-chu} + + + | 教务通知 | 教务动态 | + | ---- | ---- | + | jwtz | jwdt | + + +### 数学与统计学院 - 通知公告{#ji-shou-da-xue-shu-xue-yu-tong-ji-xue-yuan} + + + +### 创新中心 {#ji-shou-da-xue-chuang-xin-zhong-xin} + + + | 通知公告 | 学科竞赛公告 | 创新项目公告 | 竞赛新闻 | 竞赛通知 | + | ------ | ----------- | ---------- | ------ | ------- | + | tzgg | xkjs | cxtz | jsxw | jstz | +