diff --git a/docs/university.md b/docs/university.md index a7a72fd6a..11d5e8cff 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1811,7 +1811,7 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 教务处 - + | 通知公告 | 教学服务 | 教学建设 | 学生培养 | 教学资源 | | ---- | ---- | ---- | ---- | ---- | @@ -1819,9 +1819,27 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +### 研究生院 + + + +| 通知公告 | 新闻动态 | 学术信息 | 师生风采 | +| ---- | ---- | ---- | ---- | +| tzgg | xwdt | xsxx | ssfc | + + + +### 自动化学院 + + + +| 综合新闻 | 党委行政 | 人事 / 合作 | 研究生培养 | 本科生培养 | 学生工作 | 通知公告 | 学术信息 | 答辩公告 | +| ---- | ---- | ------- | ----- | ----- | ---- | ---- | ---- | ---- | +| zhxw | dwxz | rshz | yjs | bks | xsgz | tzgg | xsxx | dbgg | + ### 计算机科学与技术学院 - + | 通知公告 | 热点新闻 | 学科科研 | 教学动态 | 本科生培养 | 研究生培养 | 学生工作 | | ---- | ---- | ---- | ---- | ----- | ----- | ---- | @@ -1829,16 +1847,6 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS -### 研究生院 - - - -| 最近动态 | 研院新闻 | 上级文件 | 管理文件 | 信息服务 | -| ------ | ---- | ---- | ---- | ---- | -| latest | yyxw | sjwj | glwj | xxfw | - - - ## 南京理工大学 ### 教务处 diff --git a/lib/v2/nuaa/college/cae.js b/lib/v2/nuaa/college/cae.js new file mode 100644 index 000000000..c2f2a8822 --- /dev/null +++ b/lib/v2/nuaa/college/cae.js @@ -0,0 +1,85 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const getCookie = require('../utils/pypasswaf'); +const host = 'https://cae.nuaa.edu.cn/'; + +const map = new Map([ + ['zhxw', { title: '综合新闻 | 南京航空航天大学自动化学院', suffix: '5399/list.htm' }], + ['dwxz', { title: '党委行政 | 南京航空航天大学自动化学院', suffix: '13266/list.htm' }], + ['rshz', { title: '人事/合作 | 南京航空航天大学自动化学院', suffix: '13267/list.htm' }], + ['yjs', { title: '研究生培养 | 南京航空航天大学自动化学院', suffix: '13271/list.htm' }], + ['bks', { title: '本科生培养 | 南京航空航天大学自动化学院', suffix: '13270/list.htm' }], + ['xsgz', { title: '学生工作 | 南京航空航天大学自动化学院', suffix: '13268/list.htm' }], + ['tzgg', { title: '通知公告 | 南京航空航天大学自动化学院', suffix: '13264/list.htm' }], + ['xsxx', { title: '学术信息 | 南京航空航天大学自动化学院', suffix: '13265/list.htm' }], + ['dbgg', { title: '答辩公告 | 南京航空航天大学自动化学院', suffix: 'dbgg/list.htm' }], +]); + +module.exports = async (ctx) => { + const type = ctx.params.type; + const suffix = map.get(type).suffix; + const getDescription = Boolean(ctx.params.getDescription) || false; + const link = new URL(suffix, host).href; + const cookie = await getCookie(host); + const gotConfig = { + headers: { + cookie, + }, + }; + const response = await got(link, gotConfig); + const $ = cheerio.load(response.data); + + const list = $('#wp_news_w6 ul li') + .slice(0, 10) + .map(function () { + const info = { + title: $(this).find('a').text(), + link: $(this).find('a').attr('href'), + date: $(this).find('span').text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map((info) => { + const title = info.title || 'zhxw'; + const date = info.date; + const itemUrl = new URL(info.link, host).href; + + return ctx.cache.tryGet(itemUrl, async () => { + const arr = itemUrl.split('.'); + const pageType = arr[arr.length - 1]; + + // 南航新 WAF 过于敏感 + // 目前 description 需要遍历页面,会被 WAF 拦截导致无法输出 + // 考虑换一种获取 description 的方式或者将标题当作 title。 + let description = title + '
查看原文'; + if (getDescription) { + description = itemUrl; + if (pageType === 'htm' || pageType === 'html') { + const response = await got(itemUrl, gotConfig); + const $ = cheerio.load(response.data); + description = $('.wp_articlecontent').html() + '

查看原文'; + } + } + + const single = { + title, + link: itemUrl, + description, + pubDate: parseDate(date), + }; + return single; + }); + }) + ); + + ctx.state.data = { + title: map.get(type).title, + link, + description: '南京航空航天大学自动化学院RSS', + item: out, + }; +}; diff --git a/lib/v2/nuaa/cs/index.js b/lib/v2/nuaa/college/cs.js similarity index 73% rename from lib/v2/nuaa/cs/index.js rename to lib/v2/nuaa/college/cs.js index bc3cb3571..36eae3327 100644 --- a/lib/v2/nuaa/cs/index.js +++ b/lib/v2/nuaa/college/cs.js @@ -2,16 +2,16 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const getCookie = require('../utils/pypasswaf'); -const host = 'http://cs.nuaa.edu.cn/'; +const host = 'https://cs.nuaa.edu.cn/'; const map = new Map([ - ['tzgg', { title: '南京航空航天大学计算机科学与技术学院 -- 通知公告', suffix: 'tzgg/list.htm' }], - ['rdxw', { title: '南京航空航天大学计算机科学与技术学院 -- 热点新闻', suffix: '10846/list.htm' }], - ['xkky', { title: '南京航空航天大学计算机科学与技术学院 -- 学科科研', suffix: '10849/list.htm' }], - ['be', { title: '南京航空航天大学计算机科学与技术学院 -- 本科生培养', suffix: '10850/list.htm' }], - ['me', { title: '南京航空航天大学计算机科学与技术学院 -- 研究生培养', suffix: '10851/list.htm' }], - ['jxdt', { title: '南京航空航天大学计算机科学与技术学院 -- 教学动态', suffix: '1977/list.htm' }], - ['xsgz', { title: '南京航空航天大学计算机科学与技术学院 -- 学生工作', suffix: '1959/list.htm' }], + ['tzgg', { title: '通知公告 | 南京航空航天大学计算机科学与技术学院', suffix: 'tzgg/list.htm' }], + ['rdxw', { title: '热点新闻 | 南京航空航天大学计算机科学与技术学院', suffix: '10846/list.htm' }], + ['xkky', { title: '学科科研 | 南京航空航天大学计算机科学与技术学院', suffix: '10849/list.htm' }], + ['be', { title: '本科生培养 | 南京航空航天大学计算机科学与技术学院', suffix: '10850/list.htm' }], + ['me', { title: '研究生培养 | 南京航空航天大学计算机科学与技术学院', suffix: '10851/list.htm' }], + ['jxdt', { title: '教学动态 | 南京航空航天大学计算机科学与技术学院', suffix: '1977/list.htm' }], + ['xsgz', { title: '学生工作 | 南京航空航天大学计算机科学与技术学院', suffix: '1959/list.htm' }], ]); module.exports = async (ctx) => { @@ -20,7 +20,7 @@ module.exports = async (ctx) => { const suffix = map.get(type).suffix; const link = new URL(suffix, host).href; - const cookie = await getCookie(); + const cookie = await getCookie(host); const gotConfig = { headers: { cookie, diff --git a/lib/v2/nuaa/jwc/jwc.js b/lib/v2/nuaa/jwc/jwc.js index 8f199edb0..3710b759f 100644 --- a/lib/v2/nuaa/jwc/jwc.js +++ b/lib/v2/nuaa/jwc/jwc.js @@ -5,11 +5,11 @@ const getCookie = require('../utils/pypasswaf'); const host = 'http://aao.nuaa.edu.cn/'; const map = new Map([ - ['tzgg', { title: '南京航空航天大学教务处 -- 通知公告', suffix: '8222/list.htm' }], - ['jxfw', { title: '南京航空航天大学教务处 -- 教学服务', suffix: '8230/list.htm' }], - ['xspy', { title: '南京航空航天大学教务处 -- 学生培养', suffix: '8231/list.htm' }], - ['jxjs', { title: '南京航空航天大学教务处 -- 教学建设', suffix: '8232/list.htm' }], - ['jxzy', { title: '南京航空航天大学教务处 -- 教学资源', suffix: '8233/list.htm' }], + ['tzgg', { title: '通知公告 | 南京航空航天大学教务处', suffix: '8222/list.htm' }], + ['jxfw', { title: '教学服务 | 南京航空航天大学教务处', suffix: '8230/list.htm' }], + ['xspy', { title: '学生培养 | 南京航空航天大学教务处', suffix: '8231/list.htm' }], + ['jxjs', { title: '教学建设 | 南京航空航天大学教务处', suffix: '8232/list.htm' }], + ['jxzy', { title: '教学资源 | 南京航空航天大学教务处', suffix: '8233/list.htm' }], ]); module.exports = async (ctx) => { @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const getDescription = Boolean(ctx.params.getDescription) || false; const link = new URL(suffix, host).href; - const cookie = await getCookie(); + const cookie = await getCookie(host); const gotConfig = { headers: { cookie, @@ -52,13 +52,13 @@ module.exports = async (ctx) => { // 南航新 WAF 过于敏感 // 目前 description 需要遍历页面,会被 WAF 拦截导致无法输出 // 考虑换一种获取 description 的方式或者将标题当作 title。 - let description = title; + let description = title + '
查看原文'; if (getDescription) { description = itemUrl; if (pageType === 'htm' || pageType === 'html') { const response = await got(itemUrl, gotConfig); const $ = cheerio.load(response.data); - description = $('.wp_articlecontent').html(); + description = $('.wp_articlecontent').html() + '

查看原文'; } } diff --git a/lib/v2/nuaa/maintainer.js b/lib/v2/nuaa/maintainer.js index 1861cbdab..cf17c207a 100644 --- a/lib/v2/nuaa/maintainer.js +++ b/lib/v2/nuaa/maintainer.js @@ -1,5 +1,6 @@ module.exports = { '/cs/:type/:getDescription?': ['LogicJake', 'Seiry', 'qrzbing'], - '/jwc/:type/:getDescription?': ['arcosx', 'Seiry', 'qrzbing'], - '/yjsy/:type?': ['junfengP', 'Seiry'], + '/cae/:type/:getDescription?': ['Seiry', 'qrzbing', 'Xm798'], + '/jwc/:type/:getDescription?': ['arcosx', 'Seiry', 'qrzbing', 'Xm798'], + '/yjsy/:type/:getDescription?': ['junfengP', 'Seiry', 'Xm798'], }; diff --git a/lib/v2/nuaa/radar.js b/lib/v2/nuaa/radar.js index df521f473..b15527d30 100644 --- a/lib/v2/nuaa/radar.js +++ b/lib/v2/nuaa/radar.js @@ -13,6 +13,12 @@ module.exports = { docs: 'https://docs.rsshub.app/university.html#nan-jing-hang-kong-hang-tian-da-xue', }, ], + cae: [ + { + title: '自动化学院', + docs: 'https://docs.rsshub.app/university.html#nan-jing-hang-kong-hang-tian-da-xue', + }, + ], 'www.graduate': [ { title: '研究生院', diff --git a/lib/v2/nuaa/router.js b/lib/v2/nuaa/router.js index c906a0548..cf57ad6b5 100644 --- a/lib/v2/nuaa/router.js +++ b/lib/v2/nuaa/router.js @@ -1,5 +1,6 @@ module.exports = (router) => { - router.get('/cs/:type/:getDescription?', require('./cs/index')); + router.get('/cae/:type/:getDescription?', require('./college/cae')); + router.get('/cs/:type/:getDescription?', require('./college/cs')); router.get('/jwc/:type/:getDescription?', require('./jwc/jwc')); - router.get('/yjsy/:type?', require('./yjsy/yjsy')); + router.get('/yjsy/:type/:getDescription?', require('./yjsy/yjsy')); }; diff --git a/lib/v2/nuaa/utils/pypasswaf.js b/lib/v2/nuaa/utils/pypasswaf.js index 1135d5349..cec40e60a 100644 --- a/lib/v2/nuaa/utils/pypasswaf.js +++ b/lib/v2/nuaa/utils/pypasswaf.js @@ -1,10 +1,8 @@ -const host = 'http://aao.nuaa.edu.cn/'; - /** * async function 获取cookie * @desc 返回一个可用的cookie,使用 `got` 发起请求的时候,传入到`options.headers.cookie`即可 */ -module.exports = async function getCookie() { +module.exports = async function getCookie(host) { const browser = await require('@/utils/puppeteer')({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); diff --git a/lib/v2/nuaa/yjsy/yjsy.js b/lib/v2/nuaa/yjsy/yjsy.js index 6f21060fc..fb8d25ace 100644 --- a/lib/v2/nuaa/yjsy/yjsy.js +++ b/lib/v2/nuaa/yjsy/yjsy.js @@ -1,55 +1,80 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const host = 'http://www.graduate.nuaa.edu.cn/'; const { parseDate } = require('@/utils/parse-date'); +const getCookie = require('../utils/pypasswaf'); +const host = 'http://www.graduate.nuaa.edu.cn/'; -const map = { - latest: '2146/list.htm', - yyxw: 'yyxw/list.htm', - sjwj: 'sjwj/list.htm', - glwj: '2017/list.htm', - xxfw: '2147/list.htm', -}; - -const load = (link, ctx) => - ctx.cache.tryGet(link, async () => { - const response = await got(host + link); - const $ = cheerio.load(response.data); - const images = $('img'); - for (let k = 0; k < images.length; k++) { - $(images[k]).replaceWith(``); - } - const description = $('.wp_articlecontent').html(); - return { description }; - }); +const map = new Map([ + ['tzgg', { title: '通知公告 | 南京航空航天大学研究生院', suffix: '2145/list.htm' }], + ['xwdt', { title: '新闻动态 | 南京航空航天大学研究生院', suffix: '13276/list.htm' }], + ['xsxx', { title: '学术信息 | 南京航空航天大学研究生院', suffix: '13277/list.htm' }], + ['ssfc', { title: '师生风采 | 南京航空航天大学研究生院', suffix: '13278/list.htm' }], +]); module.exports = async (ctx) => { - const type = ctx.params.type ?? 'latest'; - const response = await got({ - method: 'get', - url: host + map[type], - }); + const type = ctx.params.type; + const suffix = map.get(type).suffix; + const getDescription = Boolean(ctx.params.getDescription) || false; + const link = new URL(suffix, host).href; + const cookie = await getCookie(host); + const gotConfig = { + headers: { + cookie, + }, + }; + const response = await got(link, gotConfig); const $ = cheerio.load(response.data); - const list = $('#news_list ul.news_ul > li').slice(0, 10).get(); - const process = await Promise.all( - list.map(async (item) => { - const a = $(item).find('a'); - const t = $(item).find('span'); - const itemUrl = a.attr('href'); - const single = { - title: a.text(), - link: new URL(itemUrl, host).href, - pubDate: parseDate(t.text(), 'YYYY-MM-DD'), + + const list = $('#wp_news_w6 ul li') + .slice(0, 10) + .map(function () { + const info = { + title: $(this).find('a').text(), + link: $(this).find('a').attr('href'), + date: $(this).find('span').text(), }; - const other = await load(itemUrl, ctx); - return { ...single, ...other }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map((info) => { + const title = info.title || 'tzgg'; + const date = info.date; + const itemUrl = new URL(info.link, host).href; + + return ctx.cache.tryGet(itemUrl, async () => { + const arr = itemUrl.split('.'); + const pageType = arr[arr.length - 1]; + + // 南航新 WAF 过于敏感 + // 目前 description 需要遍历页面,会被 WAF 拦截导致无法输出 + // 考虑换一种获取 description 的方式或者将标题当作 title。 + let description = title + '
查看原文'; + if (getDescription) { + description = itemUrl; + if (pageType === 'htm' || pageType === 'html') { + const response = await got(itemUrl, gotConfig); + const $ = cheerio.load(response.data); + description = $('.wp_articlecontent').html() + '

查看原文'; + } + } + + const single = { + title, + link: itemUrl, + description, + pubDate: parseDate(date), + }; + return single; + }); }) ); ctx.state.data = { - title: '南航研究生院', - link: host, - description: '南航研究生院RSS', - item: process, + title: map.get(type).title, + link, + description: '南京航空航天大学研究生院RSS', + item: out, }; };