diff --git a/docs/university.md b/docs/university.md index 8608da9fe9..d9737148a0 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1537,6 +1537,28 @@ type 列表: +## 南京师范大学 + +### 教务通知 + + + +| 教师通知 | 新闻动态 | 学生通知 | +| ---- | ---- | ---- | +| jstz | xwdt | xstz | + + + +### 计算机与电子信息学院 - 人工智能学院 + + + +| 学院公告 | 学院新闻 | 学生资讯 | +| ---- | ---- | ---- | +| xygg | xyxw | xszx | + + + ## 南京信息工程大学 ::: tip 提示 diff --git a/lib/v2/njnu/ceai/ceai.js b/lib/v2/njnu/ceai/ceai.js new file mode 100644 index 0000000000..6390a55ce7 --- /dev/null +++ b/lib/v2/njnu/ceai/ceai.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'xygg': + title = '学院公告'; + path = '1651'; + break; + case 'xyxw': + title = '学院新闻'; + path = '1652'; + break; + case 'xszx': + title = '学生资讯'; + path = '1659'; + break; + } + const base = 'http://ceai.njnu.edu.cn/Item/List.asp?ID=' + path; + + const response = await got({ + method: 'get', + url: base, + https: { + rejectUnauthorized: false, + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('span a').get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '南京师范大学计电人院 - ' + title, + link: 'http://ceai.njnu.edu.cn/', + description: '南京师范大学计电人院', + item: result, + }; +}; diff --git a/lib/v2/njnu/ceai/utils.js b/lib/v2/njnu/ceai/utils.js new file mode 100644 index 0000000000..dfae970257 --- /dev/null +++ b/lib/v2/njnu/ceai/utils.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +// 专门定义一个function用于加载文章内容 +async function load(link) { + // 异步请求文章 + const response = await got.get(link, { + https: { + rejectUnauthorized: false, + }, + }); + // 加载文章内容 + const $ = cheerio.load(response.data); + const dateStr = $('#xw_xinxi span:nth-child(1)').text(); + // 解析日期 + const pubDate = timezone(parseDate(dateStr, 'YYYY-MM-DD', 'zh-cn'), +8); + // 提取内容 + const description = $('#xw_content').html(); + + // 返回解析的结果 + return { description, pubDate }; +} + +const ProcessFeed = async (list, caches) => + await Promise.all( + // 遍历每一篇文章 + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title = $('a'); + // 还原相对链接为绝对链接 + const itemUrl = $title.attr('href'); + + // 列表上提取到的信息 + const single = { + title: $title.text(), + link: itemUrl, + author: '计算机与电子信息学院-人工智能学院', + guid: itemUrl, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return { ...single, ...other }; + }) + ); + +module.exports = { + ProcessFeed, +}; diff --git a/lib/v2/njnu/jwc/jwc.js b/lib/v2/njnu/jwc/jwc.js new file mode 100644 index 0000000000..ae55a7d9c1 --- /dev/null +++ b/lib/v2/njnu/jwc/jwc.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + let title, path; + switch (type) { + case 'jstz': + title = '教师通知'; + path = 'jstz.htm'; + break; + case 'xwdt': + title = '新闻动态'; + path = 'xwdt.htm'; + break; + case 'xstz': + title = '学生通知'; + path = 'xstz.htm'; + } + const base = 'http://jwc.njnu.edu.cn/index/' + path; + + const response = await got({ + method: 'get', + url: base, + https: { + rejectUnauthorized: false, + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.list_txt a').get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '南京师范大学教务处 - ' + title, + link: 'http://jwc.njnu.edu.cn/', + description: '南京师范大学教务处', + item: result, + }; +}; diff --git a/lib/v2/njnu/jwc/utils.js b/lib/v2/njnu/jwc/utils.js new file mode 100644 index 0000000000..cf6713678f --- /dev/null +++ b/lib/v2/njnu/jwc/utils.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +// 专门定义一个function用于加载文章内容 +async function load(link) { + // 异步请求文章 + const response = await got.get(link, { + https: { + rejectUnauthorized: false, + }, + }); + // 加载文章内容 + const $ = cheerio.load(response.data); + const dateStr = $('span+ span').text(); + // 解析日期 + const pubDate = timezone(parseDate(dateStr, 'YYYY-MM-DD', 'zh-cn'), +8); + // 提取内容 + const description = $('form > div').html(); + + // 返回解析的结果 + return { description, pubDate }; +} + +const ProcessFeed = async (list, caches) => { + const host = 'http://jwc.njnu.edu.cn/'; + + // 使用 Promise.all() 进行 async 并发 + return await Promise.all( + // 遍历每一篇文章 + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title = $('a'); + // 还原相对链接为绝对链接 + const itemUrl = new URL($title.attr('href'), host); + + // 列表上提取到的信息 + const single = { + title: $title.text(), + link: itemUrl, + author: '教务处', + guid: itemUrl, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return { ...single, ...other }; + }) + ); +}; + +module.exports = { + ProcessFeed, +}; diff --git a/lib/v2/njnu/maintainer.js b/lib/v2/njnu/maintainer.js new file mode 100644 index 0000000000..842d9f712c --- /dev/null +++ b/lib/v2/njnu/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/jwc/:type': ['Shujakuinkuraudo'], + '/ceai/:type': ['Shujakuinkuraudo'], +}; diff --git a/lib/v2/njnu/radar.js b/lib/v2/njnu/radar.js new file mode 100644 index 0000000000..0461019a9c --- /dev/null +++ b/lib/v2/njnu/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'njnu.edu.cn': { + _name: '南京师范大学', + ceai: [ + { + title: '计算机与电子信息学院-人工智能学院', + docs: 'https://docs.rsshub.app/university.html#nan-jing-shi-fan-da-xue', + source: '/', + target: '/njnu/ceai/xygg', + }, + ], + jwc: [ + { + title: '教务通知', + docs: 'https://docs.rsshub.app/university.html#nan-jing-shi-fan-da-xue', + source: '/', + target: '/njnu/jwc/xwdt', + }, + ], + }, +}; diff --git a/lib/v2/njnu/router.js b/lib/v2/njnu/router.js new file mode 100644 index 0000000000..825ac901ca --- /dev/null +++ b/lib/v2/njnu/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/jwc/:type', require('./jwc/jwc')); + router.get('/ceai/:type', require('./ceai/ceai')); +};