feat: add 西安交通大学教务处 (#4085)

This commit is contained in:
hoilc
2020-02-26 01:03:09 +08:00
committed by GitHub
parent 2873b0b763
commit 49c6985c0d
3 changed files with 112 additions and 0 deletions

View File

@@ -1076,6 +1076,24 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</Route> </Route>
## 西安交通大学
### 教务处
<Route author="hoilc" example="/xjtu/dean/jxxx/xytz/ksap" path="/xjtu/dean/:subpath+" :paramsDesc="['栏目路径, 支持多级, 不包括末尾的`.htm`']">
::: tip 提示
支持`http://dean.xjtu.edu.cn/`下所有**有文章列表**的栏目,
例如`http://dean.xjtu.edu.cn/gzlc.htm`, 则`subpath``gzlc`
又例`http://dean.xjtu.edu.cn/jxxx/xytz.htm`, 则`subpath``jxxx/xytz`
:::
</Route>
## 西南财经大学 ## 西南财经大学
### 经济信息工程学院 ### 经济信息工程学院

View File

@@ -2307,4 +2307,7 @@ router.get('/magireco/event_banner', require('./routes/magireco/event_banner'));
// wolley // wolley
router.get('/wolley', require('./routes/wolley/index')); router.get('/wolley', require('./routes/wolley/index'));
// 西安交大
router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean'));
module.exports = router; module.exports = router;

View File

@@ -0,0 +1,91 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const subpath = ctx.params.subpath;
const url = `http://dean.xjtu.edu.cn/${subpath.replace(/\.htm/g, '')}.htm`;
const base = url
.split('/')
.slice(0, -1)
.join('/');
const list_response = await got.get(url);
const $ = cheerio.load(list_response.data);
const subname = $('em.ma-nav a')
.slice(1)
.map(function() {
return $(this).text();
})
.get()
.join(' - ');
const list = $('.list_main_content > .list-li').get();
const parseContent = async (htmlString) => {
const $ = cheerio.load(htmlString);
const info = $('.detail_main_content > h1')
.contents()
.filter(function() {
return this.nodeType === 3;
})
.map(function() {
return $(this)
.text()
.trim();
})
.get();
const content = $('[id^="vsb_content"]');
$('form > div > ul a').each(function() {
$(this).appendTo(content);
$('<br>').appendTo(content);
});
return {
author: info[0] || '教务处',
description: content.html(),
pubDate: new Date(info[1]),
};
};
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const title = $('a');
const link = new URL(title.attr('href'), base);
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const rssitem = {
title: title.text().trim(),
link: link,
};
try {
const response = await got.get(link);
const result = await parseContent(response.data);
rssitem.description = result.description;
rssitem.author = result.author;
rssitem.pubDate = result.pubDate;
} catch (err) {
return Promise.resolve('');
}
ctx.cache.set(link, JSON.stringify(rssitem));
return Promise.resolve(rssitem);
})
);
ctx.state.data = {
title: `西安交大教务处 - ${subname}`,
link: url,
item: out.filter((item) => item !== ''),
};
};