feat: 添加派代首页,论坛和商道RSS订阅 #1974 (#2089)

* feat(rss): 添加派代首页,论坛和商道RSS订阅 #1974

* fix: fix return error
This commit is contained in:
qiwihui
2019-05-09 17:43:16 +08:00
committed by DIYgod
parent 26c4df2071
commit 4b4bd10cd4
6 changed files with 182 additions and 0 deletions
+6
View File
@@ -544,3 +544,9 @@ type 为 all 时,category 参数不支持 cost 和 free
| games | software | shishiredian | xljt | fhdq | xljt | tech | other |
</Route>
## 派代
<Route name="首页" author="qiwihui" example="/paidai" path="/paidao" />
<Route name="论坛" author="qiwihui" example="/paidai/bbs" path="/paidao/bbs" />
<Route name="商道" author="qiwihui" example="/paidai/news" path="/paidao/news" />
+5
View File
@@ -1334,4 +1334,9 @@ router.get('/dilidili/fanju/:id', require('./routes/dilidili/fanju'));
// 且听风吟福利
router.get('/qtfyfl/:category', require('./routes/qtfyfl/category'));
// 派代
router.get('/paidai', require('./routes/paidai/index'));
router.get('/paidai/bbs', require('./routes/paidai/bbs'));
router.get('/paidai/news', require('./routes/paidai/news'));
module.exports = router;
+47
View File
@@ -0,0 +1,47 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
const host = 'http://bbs.paidai.com/hot';
module.exports = async (ctx) => {
const link = host;
const response = await axios({
method: 'get',
url: link,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
});
const $ = cheerio.load(response.data);
const list = $('#index_topic_list ul li')
.slice(0, 11)
.map(function() {
const info = {
title: $(this)
.find('span.m2-li-r-1 a')
.attr('title'),
link: $(this)
.find('span.m2-li-r-1 a')
.attr('href'),
date: $(this)
.find('span.m2-li-r-2')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const link = info.link;
return await ctx.cache.tryGet(link, async () => await utils.ProcessFeed(info));
})
);
ctx.state.data = {
title: `论坛-派代`,
link: link,
item: out,
};
};
+48
View File
@@ -0,0 +1,48 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
const host = 'http://www.paidai.com/';
module.exports = async (ctx) => {
const link = host;
const response = await axios({
method: 'get',
url: link,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
});
const $ = cheerio.load(response.data);
const list = $('#topic_list ul li')
.slice(0, 11)
.map(function() {
const info = {
title: $(this)
.find('a.i_title')
.attr('title'),
link: $(this)
.find('div.li_1')
.find('a.i_title')
.attr('href'),
date: $(this)
.find('em.li_s')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const link = info.link;
return await ctx.cache.tryGet(link, async () => await utils.ProcessFeed(info));
})
);
ctx.state.data = {
title: `首页-派代`,
link: link,
item: out,
};
};
+48
View File
@@ -0,0 +1,48 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
const host = 'http://news.paidai.com/';
module.exports = async (ctx) => {
const link = host;
const response = await axios({
method: 'get',
url: link,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
});
const $ = cheerio.load(response.data);
const list = $('.news_list ul.list>li')
.slice(0, 11)
.map(function() {
const info = {
title: $(this)
.find('h3 a')
.attr('title'),
link: $(this)
.find('h3')
.find('a')
.attr('href'),
date: $(this)
.find('.post_info')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const link = info.link;
return await ctx.cache.tryGet(link, async () => await utils.ProcessFeed(info));
})
);
ctx.state.data = {
title: `商道-派代`,
link: link,
item: out,
};
};
+28
View File
@@ -0,0 +1,28 @@
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
const date = require('../../utils/date');
const ProcessFeed = async (info) => {
const title = info.title;
const itemUrl = info.link;
const itemDate = info.date;
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('#topic_content')
.html()
.trim();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: date(itemDate),
};
return single;
};
module.exports = {
ProcessFeed,
};