添加推酷周刊 (#393)

* 添加推酷周刊

* RE
This commit is contained in:
zpcc
2018-07-29 14:32:07 +08:00
committed by DIYgod
parent b4133e6005
commit 8416635f82
4 changed files with 75 additions and 0 deletions
+2
View File
@@ -185,6 +185,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- ONE · 一个
- Firefox
- Release note
- 推酷
- 周刊
</details>
+14
View File
@@ -1533,3 +1533,17 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
| 桌面 | Android | Beta | Nightly | Android Beta |
| ------- | ------- | ---- | ------- | ------------ |
| dekstop | android | beta | nightly | android-beta |
## 推酷
### 周刊
举例: [https://rsshub.app/tuicool/mags/tech](https://rsshub.app/tuicool/mags/tech)
路由: `/tuicool/mags/:type`
参数: type
| 编程狂人 | 设计匠艺 | 创业周刊 | 科技周刊 |
| -------- | -------- | -------- | -------- |
| prog | design | startup | tech |
Regular → Executable
+3
View File
@@ -351,4 +351,7 @@ router.get('/one', require('./routes/one/index'));
// Firefox
router.get('/firefox/release/:platform', require('./routes/firefox/release'));
// tuicool
router.get('/tuicool/mags/:type', require('./routes/tuicool/mags'));
module.exports = router;
+56
View File
@@ -0,0 +1,56 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
module.exports = async (ctx) => {
const type = ctx.params.type;
let url = `https://www.tuicool.com/mags/${type}`;
if (type === 'prog') {
url = 'https://www.tuicool.com/mags';
}
const res = await axios({
method: 'get',
url: url,
headers: {
'User-Agent': config.ua,
},
});
url =
'https://www.tuicool.com' +
cheerio
.load(res.data)('.mag-period-item a')
.attr('href');
const response = await axios({
method: 'get',
url: url,
headers: {
'User-Agent': config.ua,
},
});
const $ = cheerio.load(response.data);
const list = $('.article-title');
ctx.state.data = {
title: $('title').text(),
link: 'https://www.tuicool.com/',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('.title').text(),
description: `推酷:${item.find('.title').text()}`,
pubDate: new Date(
$('.period-title sub')
.text()
.substring(1, 11)
).toUTCString(),
link: `${item.find('a').attr('href')}`,
};
})
.get(),
};
};