From 1feddfa37c48bcdf80ce710cfa82f8b790a1967d Mon Sep 17 00:00:00 2001 From: ikvarxt Date: Sun, 19 Apr 2020 15:21:44 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=BE=BD?= =?UTF-8?q?=E5=AE=81=E5=B7=A5=E7=A8=8B=E6=8A=80=E6=9C=AF=E5=A4=A7=E5=AD=A6?= =?UTF-8?q?=E6=95=99=E5=8A=A1=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 10 ++++++++++ lib/router.js | 3 +++ lib/routes/universities/lntu/jwnews.js | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 lib/routes/universities/lntu/jwnews.js diff --git a/docs/university.md b/docs/university.md index 0dba433c1c..e058f05418 100644 --- a/docs/university.md +++ b/docs/university.md @@ -664,6 +664,10 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +## 教务公告 + + + ## 井冈山大学 ### 教务处通知 @@ -696,6 +700,12 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +## 辽宁工程技术大学 + +### 教务公告 + + + ## 洛阳理工学院 ### 教务处 diff --git a/lib/router.js b/lib/router.js index a86a28a357..02069acbc1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2539,4 +2539,7 @@ router.get('/girlimg/album/:tag?/:mode?', require('./routes/girlimg/album')); // etoland router.get('/etoland/:bo_table', require('./routes/etoland/board')); +// 辽宁工程技术大学教务在线公告 +router.get('/lntu/jwnews', require('./routes/universities/lntu/jwnews')); + module.exports = router; diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js new file mode 100644 index 0000000000..fd7af28b20 --- /dev/null +++ b/lib/routes/universities/lntu/jwnews.js @@ -0,0 +1,26 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; + const response = await got.get(link); + const $ = cheerio.load(response.data); + const list = $('.tr-ri li').slice(0, 10); + + ctx.state.data = { + title: '辽宁工程技术大学教务公告', + link: link, + description: '辽宁工程技术大学教务公告', + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('li a').text(), + link: item.find('li a').attr('href'), + }; + }) + .get(), + }; +}; From cad326add8bdc32383228cdf68560dc2dfdfe9b2 Mon Sep 17 00:00:00 2001 From: ikvarxt Date: Sun, 19 Apr 2020 15:34:06 +0800 Subject: [PATCH 2/6] update docs --- docs/university.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/university.md b/docs/university.md index e058f05418..025b9fe503 100644 --- a/docs/university.md +++ b/docs/university.md @@ -664,10 +664,6 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS -## 教务公告 - - - ## 井冈山大学 ### 教务处通知 From d21161a91c5a744f0687fcdb6e32d9fb815e6076 Mon Sep 17 00:00:00 2001 From: ikvarxt Date: Sun, 10 Jan 2021 10:56:55 +0800 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20add=20=E8=BE=BD=E5=AE=81=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E6=8A=80=E6=9C=AF=E5=A4=A7=E5=AD=A6=E6=95=99=E5=8A=A1?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E5=85=A8=E6=96=87=E6=8A=93=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/universities/lntu/jwnews.js | 83 +++++++++++++++++++------- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js index fd7af28b20..af5f492e49 100644 --- a/lib/routes/universities/lntu/jwnews.js +++ b/lib/routes/universities/lntu/jwnews.js @@ -1,26 +1,67 @@ +// 以下代码参考 bupt/yz.js & bupt/utils.js 修改完成,在此感谢。 + const got = require('@/utils/got'); const cheerio = require('cheerio'); +const url = require('url'); -module.exports = async (ctx) => { - const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; - const response = await got.get(link); - const $ = cheerio.load(response.data); - const list = $('.tr-ri li').slice(0, 10); +module.exports = async(ctx) => { + const meta = { + selector: { + list: '.tr-ri ul', + item: 'li', + content: '.v_news_content', + }, + url: 'http://jwzx.lntu.edu.cn/index/jwgg.htm', + } + const response = await got({ + method: 'get', + url: `${meta.url}`, + }); + const data = response.data; - ctx.state.data = { - title: '辽宁工程技术大学教务公告', - link: link, - description: '辽宁工程技术大学教务公告', - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('li a').text(), - link: item.find('li a').attr('href'), - }; - }) - .get(), - }; + const $ = cheerio.load(data); + const list = $(meta.selector.list).find(meta.selector.item).get(); + + + const res = await ProcessFeed(list, meta); + + ctx.state.data = { + title: '辽宁工程技术大学教务公告', + link: `${meta.url}`, + item: res, + }; }; + +const ProcessFeed = async(list, meta) => + await Promise.all( + list.map(async(item) => { + let $ = cheerio.load(item); + // 通过解析过后的子项地址 + const $url = url.resolve(meta.url, $('a').attr('href')); + + // 加载内容页面 + const response = await got({ + method: 'get', + url: $url, + }); + + const data = response.data; + $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML + + // 去除样式,好文明 + $('img, div, span, p, table, td, tr').removeAttr('style'); + $('style, script').remove(); + + // 截取掉「……教务处」 + let title = $('title').text().split('-')[0]; + + // 列表上提取到的信息 + return { + title: title, + description: $(meta.selector.content).html().replace(/(.*?)<\/span>/g, '$1').replace(/]*>/g, '').replace(/<\/span[^>]*>/g, ''), + link: $url, + author: '辽宁工程技术大学教务处', + guid: $url, // 文章唯一标识 + }; + }) + ); \ No newline at end of file From 0c63a29c6a6b39aa83c90dccf0fae25ec58f5a9c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 10 Jan 2021 03:19:01 +0000 Subject: [PATCH 4/6] style: auto format --- lib/routes/universities/lntu/jwnews.js | 105 +++++++++++++------------ 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js index 126949752b..ff40510565 100644 --- a/lib/routes/universities/lntu/jwnews.js +++ b/lib/routes/universities/lntu/jwnews.js @@ -4,64 +4,67 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); -module.exports = async(ctx) => { - const meta = { - selector: { - list: '.tr-ri ul', - item: 'li', - content: '.v_news_content', - }, - url: 'http://jwzx.lntu.edu.cn/index/jwgg.htm', - } - const response = await got({ - method: 'get', - url: `${meta.url}`, - }); - const data = response.data; +module.exports = async (ctx) => { + const meta = { + selector: { + list: '.tr-ri ul', + item: 'li', + content: '.v_news_content', + }, + url: 'http://jwzx.lntu.edu.cn/index/jwgg.htm', + }; + const response = await got({ + method: 'get', + url: `${meta.url}`, + }); + const data = response.data; - const $ = cheerio.load(data); - const list = $(meta.selector.list).find(meta.selector.item).get(); + const $ = cheerio.load(data); + const list = $(meta.selector.list).find(meta.selector.item).get(); + const res = await ProcessFeed(list, meta); - const res = await ProcessFeed(list, meta); - - ctx.state.data = { - title: '辽宁工程技术大学教务公告', - link: `${meta.url}`, - item: res, - }; + ctx.state.data = { + title: '辽宁工程技术大学教务公告', + link: `${meta.url}`, + item: res, + }; }; -const ProcessFeed = async(list, meta) => - await Promise.all( - list.map(async(item) => { - let $ = cheerio.load(item); - // 通过解析过后的子项地址 - const $url = url.resolve(meta.url, $('a').attr('href')); +const ProcessFeed = async (list, meta) => + await Promise.all( + list.map(async (item) => { + let $ = cheerio.load(item); + // 通过解析过后的子项地址 + const $url = url.resolve(meta.url, $('a').attr('href')); - // 加载内容页面 - const response = await got({ - method: 'get', - url: $url, - }); + // 加载内容页面 + const response = await got({ + method: 'get', + url: $url, + }); - const data = response.data; - $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML + const data = response.data; + $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML - // 去除样式,好文明 - $('img, div, span, p, table, td, tr').removeAttr('style'); - $('style, script').remove(); + // 去除样式,好文明 + $('img, div, span, p, table, td, tr').removeAttr('style'); + $('style, script').remove(); - // 截取掉「……教务处」 - let title = $('title').text().split('-')[0]; + // 截取掉「……教务处」 + const title = $('title').text().split('-')[0]; - // 列表上提取到的信息 - return { - title: title, - description: $(meta.selector.content).html().replace(/(.*?)<\/span>/g, '$1').replace(/]*>/g, '').replace(/<\/span[^>]*>/g, ''), - link: $url, - author: '辽宁工程技术大学教务处', - guid: $url, // 文章唯一标识 - }; - }) - ); + // 列表上提取到的信息 + return { + title: title, + description: $(meta.selector.content) + .html() + .replace(/(.*?)<\/span>/g, '$1') + .replace(/]*>/g, '') + .replace(/<\/span[^>]*>/g, ''), + link: $url, + author: '辽宁工程技术大学教务处', + guid: $url, // 文章唯一标识 + }; + }) + ); From 8202f67e1f08c804960219d7c89be37c361960d4 Mon Sep 17 00:00:00 2001 From: ikvarxt Date: Sun, 10 Jan 2021 20:27:09 +0800 Subject: [PATCH 5/6] fix: fetch content with tryGet --- lib/routes/universities/lntu/jwnews.js | 85 ++++++++++---------------- 1 file changed, 31 insertions(+), 54 deletions(-) diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js index 126949752b..37da2483db 100644 --- a/lib/routes/universities/lntu/jwnews.js +++ b/lib/routes/universities/lntu/jwnews.js @@ -1,67 +1,44 @@ -// 以下代码参考 bupt/yz.js & bupt/utils.js 修改完成,在此感谢。 - const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); module.exports = async(ctx) => { - const meta = { - selector: { - list: '.tr-ri ul', - item: 'li', - content: '.v_news_content', - }, - url: 'http://jwzx.lntu.edu.cn/index/jwgg.htm', - } - const response = await got({ - method: 'get', - url: `${meta.url}`, - }); - const data = response.data; + const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; + const response = await got.get(link); - const $ = cheerio.load(data); - const list = $(meta.selector.list).find(meta.selector.item).get(); + const $ = cheerio.load(response.data); + const list = $('.tr-ri ul').find('li').get(); + const res = await Promise.all( + list.map(async(item) => { + let $ = cheerio.load(item); + // 通过解析后的子项地址 + const item_link = url.resolve(link, $('a').attr('href')); - const res = await ProcessFeed(list, meta); + const description = await ctx.cache.tryGet(item_link, async() => { + const result = await got.get(item_link); + + $ = cheerio.load(result.data); + // remove style + $('img, div, span, p, table, td, tr').removeAttr('style'); + $('style, script').remove(); + + return $('.v_news_content').html().replace(/(]*>|<\/span>)/g, ""); + }); + + const rssitem = { + title: $('title').text().split('-')[0], + description: description, + link: item_link, + author: '辽宁工程技术大学教务处', + }; + return Promise.resolve(rssitem); + }) + ); ctx.state.data = { title: '辽宁工程技术大学教务公告', - link: `${meta.url}`, + link: link, item: res, }; -}; - -const ProcessFeed = async(list, meta) => - await Promise.all( - list.map(async(item) => { - let $ = cheerio.load(item); - // 通过解析过后的子项地址 - const $url = url.resolve(meta.url, $('a').attr('href')); - - // 加载内容页面 - const response = await got({ - method: 'get', - url: $url, - }); - - const data = response.data; - $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML - - // 去除样式,好文明 - $('img, div, span, p, table, td, tr').removeAttr('style'); - $('style, script').remove(); - - // 截取掉「……教务处」 - let title = $('title').text().split('-')[0]; - - // 列表上提取到的信息 - return { - title: title, - description: $(meta.selector.content).html().replace(/(.*?)<\/span>/g, '$1').replace(/]*>/g, '').replace(/<\/span[^>]*>/g, ''), - link: $url, - author: '辽宁工程技术大学教务处', - guid: $url, // 文章唯一标识 - }; - }) - ); +}; \ No newline at end of file From dbf27ec7087653fc4341e913c73232ebb0e3e6f3 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 10 Jan 2021 12:35:06 +0000 Subject: [PATCH 6/6] style: auto format --- lib/routes/universities/lntu/jwnews.js | 66 +++++++++++++------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js index 21074bb919..79752d2119 100644 --- a/lib/routes/universities/lntu/jwnews.js +++ b/lib/routes/universities/lntu/jwnews.js @@ -2,43 +2,45 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); -module.exports = async(ctx) => { - const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; - const response = await got.get(link); +module.exports = async (ctx) => { + const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; + const response = await got.get(link); - const $ = cheerio.load(response.data); - const list = $('.tr-ri ul').find('li').get(); + const $ = cheerio.load(response.data); + const list = $('.tr-ri ul').find('li').get(); - const res = await Promise.all( - list.map(async(item) => { - let $ = cheerio.load(item); - // 通过解析后的子项地址 - const item_link = url.resolve(link, $('a').attr('href')); + const res = await Promise.all( + list.map(async (item) => { + let $ = cheerio.load(item); + // 通过解析后的子项地址 + const item_link = url.resolve(link, $('a').attr('href')); - const description = await ctx.cache.tryGet(item_link, async() => { - const result = await got.get(item_link); + const description = await ctx.cache.tryGet(item_link, async () => { + const result = await got.get(item_link); - $ = cheerio.load(result.data); - // remove style - $('img, div, span, p, table, td, tr').removeAttr('style'); - $('style, script').remove(); + $ = cheerio.load(result.data); + // remove style + $('img, div, span, p, table, td, tr').removeAttr('style'); + $('style, script').remove(); - return $('.v_news_content').html().replace(/(]*>|<\/span>)/g, ""); - }); + return $('.v_news_content') + .html() + .replace(/(]*>|<\/span>)/g, ''); + }); - const rssitem = { - title: $('title').text().split('-')[0], - description: description, - link: item_link, - author: '辽宁工程技术大学教务处', - }; - return Promise.resolve(rssitem); - }) - ); + const rssitem = { + title: $('title').text().split('-')[0], + description: description, + link: item_link, + author: '辽宁工程技术大学教务处', + }; + return Promise.resolve(rssitem); + }) + ); - ctx.state.data = { - title: '辽宁工程技术大学教务公告', - link: link, - item: res, - }; + ctx.state.data = { + title: '辽宁工程技术大学教务公告', + link: link, + item: res, + }; };