From 16e2606b17e45e27fbe380e198e759fbbf0bf750 Mon Sep 17 00:00:00 2001 From: Jim Kirisame Date: Sun, 17 Jul 2022 20:10:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B9=BF=E4=B8=9C?= =?UTF-8?q?=E5=B7=A5=E4=B8=9A=E5=A4=A7=E5=AD=A6=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E6=96=87=E7=BD=91=20(#10231)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 广东工业大学通知公文网 * feat!: remove not working route --- docs/university.md | 10 +- lib/router.js | 2 +- lib/v2/gdut/maintainer.js | 3 + lib/{routes/universities => v2}/gdut/news.js | 4 + lib/v2/gdut/oa_news.js | 214 +++++++++++++++++++ lib/v2/gdut/radar.js | 13 ++ lib/v2/gdut/router.js | 3 + 7 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 lib/v2/gdut/maintainer.js rename lib/{routes/universities => v2}/gdut/news.js (98%) create mode 100644 lib/v2/gdut/oa_news.js create mode 100644 lib/v2/gdut/radar.js create mode 100644 lib/v2/gdut/router.js diff --git a/docs/university.md b/docs/university.md index d6ce639de..37c368198 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1001,9 +1001,15 @@ xskb1 对应 ## 广东工业大学 -### 校内新闻网 +### 通知公文网 - + + +| 校内简讯 | 校内通知 | 公示公告 | 招标公告 | 招标结果 | +| ---- | ------ | ------------ | ------------- | ------------- | +| news | notice | announcement | tender_invite | tender_result | + + ## 广东海洋大学 diff --git a/lib/router.js b/lib/router.js index 113a2a9ce..704752882 100644 --- a/lib/router.js +++ b/lib/router.js @@ -588,7 +588,7 @@ router.get('/scnu/library', lazyloadRouteHandler('./routes/universities/scnu/lib router.get('/scnu/cs/match', lazyloadRouteHandler('./routes/universities/scnu/cs/match')); // 广东工业大学 -router.get('/gdut/news', lazyloadRouteHandler('./routes/universities/gdut/news')); +// router.get('/gdut/news', lazyloadRouteHandler('./routes/universities/gdut/news')); // 中国科学院 router.get('/cas/sim/academic', lazyloadRouteHandler('./routes/universities/cas/sim/academic')); diff --git a/lib/v2/gdut/maintainer.js b/lib/v2/gdut/maintainer.js new file mode 100644 index 000000000..68e3591b9 --- /dev/null +++ b/lib/v2/gdut/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/oa_news/:type?': ['Jim Kirisame'], +}; diff --git a/lib/routes/universities/gdut/news.js b/lib/v2/gdut/news.js similarity index 98% rename from lib/routes/universities/gdut/news.js rename to lib/v2/gdut/news.js index 161fcebfc..f75e644ed 100644 --- a/lib/routes/universities/gdut/news.js +++ b/lib/v2/gdut/news.js @@ -1,3 +1,5 @@ +/* Removed due to news.gdut.edu.cn no longer exists. + const got = require('@/utils/got'); const cheerio = require('cheerio'); @@ -160,3 +162,5 @@ module.exports = async (ctx) => { item: out.length > 0 ? out : articleList, }; }; + +*/ diff --git a/lib/v2/gdut/oa_news.js b/lib/v2/gdut/oa_news.js new file mode 100644 index 000000000..fa1e2a48b --- /dev/null +++ b/lib/v2/gdut/oa_news.js @@ -0,0 +1,214 @@ +const got = require('@/utils/got'); +const wait = require('@/utils/wait'); +const cheerio = require('cheerio'); +const { CookieJar } = require('tough-cookie'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const asyncPool = require('tiny-async-pool'); + +const site = 'https://oas.gdut.edu.cn/seeyon'; +const typeMap = { + news: { + id: '-4899485396563308862', + name: '校内简讯', + publish: false, + }, + notice: { + id: '5854888065150372255', + name: '校内通知', + publish: false, + }, + announcement: { + id: '5821359576359193913', + name: '公示公告', + publish: false, + }, + tender_result: { + id: '-1226046021292568614', + name: '招标结果', + publish: true, + }, + tender_invite: { + id: '-3656117696093796045', + name: '招标公告', + publish: true, + }, +}; + +function getArg(type) { + if (type.publish) { + return JSON.stringify([ + { + pageSize: '20', + pageNo: 1, + listType: '1', + spaceType: '', + spaceId: '', + typeId: type.id, + condition: 'publishDepartment', + textfield1: '', + textfield2: '', + myNews: '', + }, + ]); + } else { + return JSON.stringify([ + { + pageSize: '20', + pageNo: 1, + listType: '1', + spaceType: '2', + spaceId: '', + typeId: '', + condition: 'publishDepartment', + textfield1: '', + textfield2: '', + myNews: '', + fragmentId: type.id, + ordinal: '0', + panelValue: 'designated_value', + }, + ]); + } +} + +module.exports = async (ctx) => { + const typeParam = ctx.params.type ?? 'notice'; + if (typeMap[typeParam] === undefined) { + throw Error('通知类型' + typeParam + '未定义'); + } + + const type = typeMap[typeParam]; + + // 获取cookie + const cookieJar = new CookieJar(); + await got(site + '/main.do', { + cookieJar, + }); + + // 获取文章列表 + const listUrl = '/ajax.do?method=ajaxAction&managerName=newsDataManager'; + const resp = await got.post(site + listUrl, { + cookieJar, + form: { + managerMethod: 'findListDatas', + arguments: getArg(type), + }, + }); + + if (!resp.data.list) { + throw Error('文章列表获取失败,可能是被临时限制了访问,请稍后重试'); + } + + // 构造文章数组 + const articles = []; + resp.data.list.forEach((item) => { + articles.push({ + title: item.title, + guid: item.id, + link: site + '/newsData.do?method=newsView&newsId=' + item.id, + pubDate: timezone(parseDate(item.publishDate1), +8), + author: item.publishUserDepart, + category: item.typeName, + }); + }); + + // 获取实际的文章内容 + for await (const data of asyncPool(2, articles, async (data) => { + const link = data.link; + data.description = await ctx.cache.tryGet(link, async () => { + // 获取数据 + const response = await got(link, { + cookieJar, + }); + + const $ = cheerio.load(response.data); + const node = $('#content'); + // 清理样式 + node.find('*') + .filter(function () { + return this.type === 'comment' || this.tagName === 'meta' || this.tagName === 'style'; + }) + .remove(); + node.find('*') + .contents() + .filter(function () { + return this.type === 'comment' || this.tagName === 'meta' || this.tagName === 'style'; + }) + .remove(); + node.find('*').each(function () { + if (this.attribs.style !== undefined) { + const newSty = this.attribs.style + .split(';') + .filter((s) => { + const styBlocklist = ['color:rgb(0,0,0)', 'color:black', 'background:rgb(255,255,255)', 'background:white', 'text-align:left', 'text-align:justify', 'font-style:normal', 'font-weight:normal']; + const styPrefixBlocklist = [ + 'font-family', + 'font-size', + 'background', + 'text-autospace', + 'text-transform', + 'letter-spacing', + 'line-height', + 'padding', + 'margin', + 'text-justify', + 'word-break', + 'vertical-align', + 'mso-', + '-ms-', + ]; + const sty = s.trim(); + if (styBlocklist.includes(sty.replace(/\s+/g, ''))) { + return false; + } + for (const prefix of styPrefixBlocklist) { + if (sty.startsWith(prefix)) { + return false; + } + } + return true; + }) + .join(';'); + if (newSty) { + this.attribs.style = newSty; + } else { + delete this.attribs.style; + } + } + if (this.attribs.class) { + if (this.attribs.class.trim().startsWith('Mso')) { + delete this.attribs.class; + } + } + if (this.attribs.lang) { + delete this.attribs.lang; + } + if (this.tagName === 'font' || this.tagName === 'o:p') { + $(this).replaceWith(this.childNodes); + } + if (this.tagName === 'span' && !this.attribs.style) { + $(this).replaceWith(this.childNodes); + } + }); + node.find('span').each(function () { + if (this.childNodes.length === 0) { + $(this).remove(); + } + }); + + // 防止太快被Ban + await wait(500); + return node.html(); + }); + })) { + data; + } + + ctx.state.data = { + title: `广东工业大学新闻通知网 - ` + type.name, + link: site, + description: `广东工业大学新闻通知网`, + item: articles, + }; +}; diff --git a/lib/v2/gdut/radar.js b/lib/v2/gdut/radar.js new file mode 100644 index 000000000..137f796c2 --- /dev/null +++ b/lib/v2/gdut/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'gdut.edu.cn': { + _name: '广东工业大学', + oas: [ + { + title: '通知公文网', + docs: 'https://docs.rsshub.app/university.html#guang-dong-gong-ye-da-xue-tong-zhi-gong-wen-wang', + source: '/seeyon', + target: '/gdut/oa_news/', + }, + ], + }, +}; diff --git a/lib/v2/gdut/router.js b/lib/v2/gdut/router.js new file mode 100644 index 000000000..756a34dc1 --- /dev/null +++ b/lib/v2/gdut/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/oa_news/:type?', require('./oa_news')); +};