feat: 西南财经大学经济信息工程学院 (#2117)

* add: 西南财经大学经济信息工程学院

* fix: name, cache  and Date
This commit is contained in:
Hivol
2019-05-13 16:29:43 +08:00
committed by DIYgod
parent 6e3753012c
commit 745d4eb3f1
3 changed files with 89 additions and 0 deletions

View File

@@ -781,6 +781,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</Route>
## 西南财经大学
### 经济信息工程学院
<Route author="Hivol" example="/swufe/seie/tzgg" path="/universities/swufe/seie/:type?" :paramsDesc="['分类名(默认为tzgg)']" >
| 学院新闻 | 通知公告 |
| -------- | -------- |
| xyxw | tzgg |
</Route>
## 西南科技大学
### 教务处新闻

View File

@@ -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;

View File

@@ -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,
};
};