From 8495a355f1bca9a4cda747b54a6542404a237d33 Mon Sep 17 00:00:00 2001 From: evnydd0sf Date: Thu, 1 Sep 2022 00:35:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=97=E4=BA=AC=E8=89=BA=E6=9C=AF?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E5=AE=98=E7=BD=91=EF=BC=8C=E5=8F=8C=E9=A6=A8?= =?UTF-8?q?=E7=BD=91=EF=BC=8C=E8=AE=BE=E8=AE=A1=E5=AD=A6=E9=99=A2=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BF=A1=E6=81=AF=20(#10664)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 南京艺术学院研究生院 * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/radar.js Co-authored-by: Tony * Update lib/v2/nua/radar.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update docs/university.md Co-authored-by: Tony * Update docs/university.md Co-authored-by: Tony * 优化代码 * 优化 * update * 补充南京艺术学院 * fix * fix * fix * 更新南京艺术学院数据源。 * 更新南京艺术学院数据源。 * fix * fix * update * fix doc * fix * Update lib/v2/nua/radar.js Co-authored-by: Tony * fix: yarn.lock permission * style: auto format * fix double fetch same page * Update dc.js * Revert "Merge branch 'master' of https://github.com/evnydd0sf/RSS-Hub" This reverts commit dd56f9469b5b2462d482c202ae798b3f159f243e, reversing changes made to d900050eb8271d0f566070eb58c2c9d87ccd6e53. * fix * Revert "fix" This reverts commit 820ff88120d4fb4fc2bdcd8ee52229d1bfb83c17. * Revert "Revert "Merge branch 'master' of https://github.com/evnydd0sf/RSS-Hub"" This reverts commit ce67e0b53c231a8a8527b7407211aff1ab7e50d4. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/university.md | 42 ++++++++++++++++++++++++++-- lib/v2/nua/dc.js | 53 +++++++++++++++++++++++++++++++++++ lib/v2/nua/gra.js | 53 ++++++----------------------------- lib/v2/nua/index.js | 22 +++++++++++++++ lib/v2/nua/maintainer.js | 3 ++ lib/v2/nua/radar.js | 24 ++++++++++++++++ lib/v2/nua/router.js | 3 ++ lib/v2/nua/sxw.js | 22 +++++++++++++++ lib/v2/nua/utils.js | 60 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 236 insertions(+), 46 deletions(-) create mode 100644 lib/v2/nua/dc.js create mode 100644 lib/v2/nua/index.js create mode 100644 lib/v2/nua/sxw.js create mode 100644 lib/v2/nua/utils.js diff --git a/docs/university.md b/docs/university.md index 04b71bf0e..eba308673 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2059,11 +2059,49 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ## 南京艺术学院 +### 官网信息 + + + +| 新闻模块 | 参数 | +| ---- | --- | +| 公告 | 346 | +| 南艺要闻 | 332 | + + + +### 双馨网 + + + +| 新闻模块 | 参数 | +| ---- | --- | +| 校园电视 | 230 | +| 院部动态 | 232 | +| 动感校园 | 233 | +| 招就指南 | 234 | +| 南艺院报 | 236 | + + + +### 设计学院 + + + +| 新闻模块 | 参数 | +| ---------- | ------- | +| 学院新闻 NEWS | news | +| 教学 TEACH | teach | +| 项目 PROJECT | project | +| 党团 PARTY | party | + + + ### 研究生处 - + -| 种类名 | 参数 | +| 新闻模块 | 参数 | | ----- | ---- | | 招生工作 | 1959 | | 培养工作 | 1962 | diff --git a/lib/v2/nua/dc.js b/lib/v2/nua/dc.js new file mode 100644 index 000000000..a5e9d8af1 --- /dev/null +++ b/lib/v2/nua/dc.js @@ -0,0 +1,53 @@ +// const got = require('@/utils/got'); +// const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + const baseUrl = 'https://dc.nua.edu.cn'; + + let listName; + let listDate; + let artiContent; + let webPageName; + + switch (type) { + case 'news': + listName = 'li.pre35.left li.news_list'; + listDate = '.date'; + artiContent = '.article'; + webPageName = 'li.pre35.left .big_title'; + break; + case 'teach': + listName = 'li.pre65.right li.effects'; + listDate = '.date'; + artiContent = '.article'; + webPageName = 'li.pre65.right .big_title'; + break; + case 'project': + listName = 'ul.center div.center_list_img'; + listDate = '.date'; + artiContent = '.article'; + webPageName = 'ul.center .big_title'; + break; + case 'party': + listName = 'div.pre35.right li.party_list'; + listDate = '.date'; + artiContent = '.article'; + webPageName = 'div.pre35.right .big_title'; + break; + default: + throw Error(`暂不支持对${type}的订阅`); + } + + const items = await util.ProcessList(baseUrl, baseUrl, listName, listDate, webPageName); + const results = await util.ProcessFeed(items[0], artiContent, ctx.cache); + + ctx.state.data = { + title: 'NUA-设计学院-' + items[1], + link: baseUrl, + description: '南京艺术学院 设计学院 ' + items[1], + item: results, + }; +}; diff --git a/lib/v2/nua/gra.js b/lib/v2/nua/gra.js index be538fb3b..4a80156e8 100644 --- a/lib/v2/nua/gra.js +++ b/lib/v2/nua/gra.js @@ -1,56 +1,21 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +const util = require('./utils'); const baseUrl = 'https://grad.nua.edu.cn'; module.exports = async (ctx) => { const type = ctx.params.type; const newsUrl = `${baseUrl}/${type}/list.htm`; + const listName = 'li.list_item'; + const artiContent = '.read'; + const listDate = '.Article_PublishDate'; + const webPageName = '.col_title'; - const response = await got(newsUrl, { - https: { - rejectUnauthorized: false, - }, - }); - - const data = response.data; - const $ = cheerio.load(data); - const pagename = $('.col_title').text(); - - const items = $('li.list_item') - .toArray() - .map((item) => { - item = $(item); - return { - link: baseUrl + item.find('a').attr('href'), - title: item.find('a').attr('title'), - pubDate: timezone(parseDate(item.find('.Article_PublishDate').first().text(), 'YYYY-MM-DD'), +8), - }; - }); - - const results = await Promise.all( - items.map((item) => - ctx.cache.tryGet(item.link, async () => { - const result = await got(item.link, { - https: { - rejectUnauthorized: false, - }, - }); - const $ = cheerio.load(result.data); - - item.author = $('.arti_publisher').text(); - item.description = $('.read').html(); - - return item; - }) - ) - ); + const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); + const results = await util.ProcessFeed(items[0], artiContent, ctx.cache); ctx.state.data = { - title: 'NUA-研究生处-' + pagename, + title: 'NUA-研究生处-' + items[1], link: `${baseUrl}/${type}/list.htm`, - description: '南京艺术学院研究生处' + pagename, + description: '南京艺术学院 研究生处 ' + items[1], item: results, }; }; diff --git a/lib/v2/nua/index.js b/lib/v2/nua/index.js new file mode 100644 index 000000000..a50b52481 --- /dev/null +++ b/lib/v2/nua/index.js @@ -0,0 +1,22 @@ +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + const baseUrl = 'https://www.nua.edu.cn'; + const newsUrl = `${baseUrl}/${type}/list.htm`; + const listName = 'li.news'; + const listDate = '.news_meta'; + const webPageName = '.col_title'; + + const artiContent = '.read'; + const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); + const results = await util.ProcessFeed(items[0], artiContent, ctx.cache); + + ctx.state.data = { + title: 'NUA-' + items[1], + link: newsUrl, + description: '南京艺术学院 ' + items[1], + item: results, + }; +}; diff --git a/lib/v2/nua/maintainer.js b/lib/v2/nua/maintainer.js index 187c84ed1..6d4282961 100644 --- a/lib/v2/nua/maintainer.js +++ b/lib/v2/nua/maintainer.js @@ -1,3 +1,6 @@ module.exports = { + '/dc/:type': ['evnydd0sf'], '/gra/:type': ['evnydd0sf'], + '/index/:type': ['evnydd0sf'], + '/sxw/:type': ['evnydd0sf'], }; diff --git a/lib/v2/nua/radar.js b/lib/v2/nua/radar.js index a7e471ef0..9052e31d1 100644 --- a/lib/v2/nua/radar.js +++ b/lib/v2/nua/radar.js @@ -1,6 +1,30 @@ module.exports = { 'nua.edu.cn': { _name: '南京艺术学院', + index: [ + { + title: '官网信息', + docs: 'https://docs.rsshub.app/university.html#nan-jing-yi-shu-xue-yuan', + source: ['/:type/list.htm'], + target: '/nua/index/:type', + }, + ], + sxw: [ + { + title: '双馨网', + docs: 'https://docs.rsshub.app/university.html#nan-jing-yi-shu-xue-yuan', + source: ['/:type/list.htm'], + target: '/nua/sxw/:type', + }, + ], + dc: [ + { + title: '设计学院', + docs: 'https://docs.rsshub.app/university.html#nan-jing-yi-shu-xue-yuan', + source: ['/:type/list.htm'], + target: '/nua/dc/:type', + }, + ], grad: [ { title: '研究生处', diff --git a/lib/v2/nua/router.js b/lib/v2/nua/router.js index 0157a1edb..c7ac0eec4 100644 --- a/lib/v2/nua/router.js +++ b/lib/v2/nua/router.js @@ -1,3 +1,6 @@ module.exports = function (router) { + router.get('/dc/:type', require('./dc')); router.get('/gra/:type', require('./gra')); + router.get('/index/:type', require('./index')); + router.get('/sxw/:type', require('./sxw')); }; diff --git a/lib/v2/nua/sxw.js b/lib/v2/nua/sxw.js new file mode 100644 index 000000000..dc2d45490 --- /dev/null +++ b/lib/v2/nua/sxw.js @@ -0,0 +1,22 @@ +const util = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + const baseUrl = 'https://sxw.nua.edu.cn'; + const newsUrl = `${baseUrl}/${type}/list.htm`; + const listName = 'li.list_item'; + const listDate = '.Article_PublishDate'; + const webPageName = '.Column_Anchor'; + + const artiContent = '.read'; + const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); + const results = await util.ProcessFeed(items[0], artiContent, ctx.cache); + + ctx.state.data = { + title: 'NUA-双馨网-' + items[1], + link: newsUrl, + description: '南京艺术学院 双馨网 ' + items[1], + item: results, + }; +}; diff --git a/lib/v2/nua/utils.js b/lib/v2/nua/utils.js new file mode 100644 index 000000000..ee3fb34b4 --- /dev/null +++ b/lib/v2/nua/utils.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) { + const result = await got(newsUrl, { + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(result.data); + + const pageName = $(webPageName).text(); + + let artiLink; + + const items = $(listName) + .toArray() + .map((item) => { + item = $(item); + if (item.find('a').attr('href').includes('http')) { + artiLink = item.find('a').attr('href'); + } else { + artiLink = baseUrl + item.find('a').attr('href'); + } + + return { + link: artiLink, + title: item.find('a').attr('title'), + pubDate: timezone(parseDate(item.find(listDate).first().text(), 'YYYY-MM-DD'), +8), + }; + }); + + return [items, pageName]; +} + +const ProcessFeed = async (items, artiContent, cache) => + await Promise.all( + items.map((item) => + cache.tryGet(item.link, async () => { + const result = await got(item.link, { + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(result.data); + + item.author = $('.arti_publisher').text() + ' ' + $('.arti_views').text(); + item.description = $(artiContent).html(); + + return item; + }) + ) + ); + +module.exports = { + ProcessList, + ProcessFeed, +};