From 745d4eb3f1abe7cf95aa5e7cd34d2777e7794be3 Mon Sep 17 00:00:00 2001 From: Hivol <31159723+Hivol@users.noreply.github.com> Date: Mon, 13 May 2019 16:29:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A5=BF=E5=8D=97=E8=B4=A2=E7=BB=8F?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E7=BB=8F=E6=B5=8E=E4=BF=A1=E6=81=AF=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E5=AD=A6=E9=99=A2=20(#2117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add: 西南财经大学经济信息工程学院 * fix: name, cache and Date --- docs/university.md | 12 ++++ lib/router.js | 3 + lib/routes/universities/swufe/seie/index.js | 74 +++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 lib/routes/universities/swufe/seie/index.js diff --git a/docs/university.md b/docs/university.md index c64bd0e3e2..c40da0cfa0 100644 --- a/docs/university.md +++ b/docs/university.md @@ -781,6 +781,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 西南财经大学 + +### 经济信息工程学院 + + + +| 学院新闻 | 通知公告 | +| -------- | -------- | +| xyxw | tzgg | + + + ## 西南科技大学 ### 教务处新闻 diff --git a/lib/router.js b/lib/router.js index 6086842db1..55359d1deb 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1360,4 +1360,7 @@ router.get('/manhuadb/comics/:id', require('./routes/manhuadb/comics')); // 观察者风闻话题 router.get('/guanchazhe/topic/:id', require('./routes/guanchazhe/topic')); +// 西南财经大学 +router.get('/swufe/seie/:type?', require('./routes/universities/swufe/seie')); + module.exports = router; diff --git a/lib/routes/universities/swufe/seie/index.js b/lib/routes/universities/swufe/seie/index.js new file mode 100644 index 0000000000..f80dc722a0 --- /dev/null +++ b/lib/routes/universities/swufe/seie/index.js @@ -0,0 +1,74 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const listUrl = 'https://it.swufe.edu.cn/index/'; +const baseUrl = 'https://it.swufe.edu.cn/'; + +const map = new Map([['xyxw', { title: '西南财经大学经济信息工程学院 -- 学院新闻', suffix: 'xyxw.htm' }], ['tzgg', { title: '西南财经大学经济信息工程学院 -- 通知公告', suffix: 'tzgg.htm' }]]); + +module.exports = async (ctx) => { + const type = ctx.params.type || 'tzgg'; + const suffix = map.get(type).suffix; + + const link = listUrl + suffix; + const response = await axios.get(link); + + const data = response.data; + const $ = cheerio.load(data); + + const list = $('div[class="article-list"] ul li a') + .slice(0, 10) + .map(function() { + const info = { + link: $(this) + .attr('href') + .slice(2), + title: $(this) + .children('span') + .first() + .text(), + date: $(this) + .children('span') + .last() + .text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(baseUrl, info.link); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + + const single = { + title: title, + link: itemUrl, + description: $('.article-main') + .html() + .replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`) + .trim(), + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: map.get(type).title, + link: link, + description: '西南财经大学经济信息工程学院RSS', + item: out, + }; +};