feat: Add Unix Socket Support && rss: Add shmtu route (#285)
* feat: Add Unix Socket Support * rss: Add shmtu route * fix: docs & bugs
This commit is contained in:
@@ -142,6 +142,10 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
- Lookup Torrents by IMDB ID(根据 IMDB ID 查找种子)
|
||||
- 什么值得买
|
||||
- 关键词
|
||||
- 上海海事大学
|
||||
- 学术讲座
|
||||
- 通知公告
|
||||
- 教务信息
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
module.exports = {
|
||||
port: process.env.PORT || 1200, // 监听端口
|
||||
connect: {
|
||||
port: process.env.PORT || 1200, // 监听端口
|
||||
socket: process.env.SOCKET || null, // 监听 Unix Socket, null 为禁用
|
||||
},
|
||||
cacheType: process.env.CACHE_TYPE || 'memory', // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存
|
||||
cacheExpire: process.env.CACHE_EXPIRE || 5 * 60, // 缓存时间,单位为秒
|
||||
ua: process.env.UA || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
|
||||
|
||||
@@ -1130,3 +1130,29 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
||||
路由: `/smzdm/keyword/:keyword`
|
||||
|
||||
参数: keyword,你想订阅的关键词
|
||||
|
||||
## 上海海事大学
|
||||
|
||||
### 学术讲座
|
||||
|
||||
举例: [https://rsshub.app/shmtu/events](https://rsshub.app/shmtu/events)
|
||||
|
||||
路由: `/shmtu/events`
|
||||
|
||||
参数: 无
|
||||
|
||||
### 通知公告
|
||||
|
||||
举例: [https://rsshub.app/shmtu/notes](https://rsshub.app/shmtu/notes)
|
||||
|
||||
路由: `/shmtu/notes`
|
||||
|
||||
参数: 无
|
||||
|
||||
### 教务信息
|
||||
|
||||
举例: [https://rsshub.app/shmtu/jwc/1](https://rsshub.app/shmtu/jwc/1)
|
||||
|
||||
路由: `/shmtu/jwc/:type`
|
||||
|
||||
参数: type,1 为教务新闻,2 为教务公告
|
||||
|
||||
@@ -329,6 +329,8 @@ gcloud app deploy
|
||||
|
||||
`PORT`: 监听端口,默认为 `1200`
|
||||
|
||||
`SOCKET`: 监听 Unix Socket,默认为 `null`
|
||||
|
||||
`CACHE_TYPE`: 缓存类型,可为 `memory` 和 `redis`,设为空可以禁止缓存,默认为 `memory`
|
||||
|
||||
`CACHE_EXPIRE`: 缓存过期时间,单位为秒,默认 300
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Koa = require('koa');
|
||||
|
||||
const fs = require('fs');
|
||||
const logger = require('./utils/logger');
|
||||
const config = require('./config');
|
||||
|
||||
@@ -83,4 +83,19 @@ if (config.cacheType === 'memory') {
|
||||
// router
|
||||
app.use(router.routes()).use(router.allowedMethods());
|
||||
|
||||
app.listen(config.port, parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
|
||||
// connect
|
||||
if (config.connect.port) {
|
||||
app.listen(config.connect.port, parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
|
||||
logger.info('Listening Port ' + config.connect.port);
|
||||
}
|
||||
if (config.connect.socket) {
|
||||
if (fs.existsSync(config.connect.socket)) {
|
||||
fs.unlinkSync(config.connect.socket);
|
||||
}
|
||||
app.listen(config.connect.socket, parseInt(config.listenInaddrAny) ? null : '127.0.0.1');
|
||||
logger.info('Listening Unix Socket ' + config.connect.socket);
|
||||
process.on('SIGINT', () => {
|
||||
fs.unlinkSync(config.connect.socket);
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -293,4 +293,9 @@ router.get('/eztv/torrents/:imdb_id', require('./routes/eztv/imdb'));
|
||||
// 什么值得买
|
||||
router.get('/smzdm/keyword/:keyword', require('./routes/smzdm/keyword'));
|
||||
|
||||
// SHMTU
|
||||
router.get('/shmtu/events', require('./routes/shmtu/events'));
|
||||
router.get('/shmtu/notes', require('./routes/shmtu/notes'));
|
||||
router.get('/shmtu/jwc/:type', require('./routes/shmtu/jwc'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const host = 'http://www.shmtu.edu.cn';
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: host + '/events',
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: host,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const text = $('tr', 'tbody');
|
||||
|
||||
ctx.state.data = {
|
||||
title: '上海海事大学 学术讲座',
|
||||
link: host + '/events',
|
||||
description: '上海海事大学 学术讲座',
|
||||
item:
|
||||
text &&
|
||||
text
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.title').text(),
|
||||
description: '发布部门 - ' + item.find('.department').text(),
|
||||
pubDate: item
|
||||
.find('span')
|
||||
.find('span')
|
||||
.attr('content'),
|
||||
link: host + item.find('a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const host = 'http://jwc.shmtu.edu.cn/Information/';
|
||||
let type = ctx.params.type;
|
||||
let info = '教务新闻';
|
||||
if (type === '2') {
|
||||
info = '教务公告';
|
||||
} else {
|
||||
type = '1';
|
||||
}
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: host + `MoreInfo.aspx?type=${type}`,
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: host,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const text = $('.gvRow', '.tdMCViewList');
|
||||
|
||||
ctx.state.data = {
|
||||
title: `上海海事大学 ${info}`,
|
||||
link: host + `MoreInfo.aspx?type=${type}`,
|
||||
description: `上海海事大学 ${info}`,
|
||||
item:
|
||||
text &&
|
||||
text
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').attr('title'),
|
||||
description:
|
||||
'信息类别 - ' +
|
||||
$('.gvItemNormal', item)
|
||||
.slice(1, 2)
|
||||
.text(),
|
||||
pubDate: $('.gvItemNormal', item)
|
||||
.slice(4)
|
||||
.text(),
|
||||
link: host + item.find('a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const host = 'http://www.shmtu.edu.cn';
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: host + '/notes',
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Referer: host,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const text = $('tr', 'tbody');
|
||||
|
||||
ctx.state.data = {
|
||||
title: '上海海事大学 通知公告',
|
||||
link: host + '/notes',
|
||||
description: '上海海事大学 通知公告',
|
||||
item:
|
||||
text &&
|
||||
text
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.title').text(),
|
||||
description: '发布部门 - ' + item.find('.department').text(),
|
||||
pubDate: item
|
||||
.find('span')
|
||||
.find('span')
|
||||
.attr('content'),
|
||||
link: host + item.find('a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user