From 4b4bd10cd41efb3e24e2a797ec3f948a791c4031 Mon Sep 17 00:00:00 2001 From: qiwihui Date: Thu, 9 May 2019 17:43:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B4=BE=E4=BB=A3?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=EF=BC=8C=E8=AE=BA=E5=9D=9B=E5=92=8C=E5=95=86?= =?UTF-8?q?=E9=81=93RSS=E8=AE=A2=E9=98=85=20#1974=20(#2089)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(rss): 添加派代首页,论坛和商道RSS订阅 #1974 * fix: fix return error --- docs/other.md | 6 +++++ lib/router.js | 5 ++++ lib/routes/paidai/bbs.js | 47 +++++++++++++++++++++++++++++++++++++ lib/routes/paidai/index.js | 48 ++++++++++++++++++++++++++++++++++++++ lib/routes/paidai/news.js | 48 ++++++++++++++++++++++++++++++++++++++ lib/routes/paidai/utils.js | 28 ++++++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 lib/routes/paidai/bbs.js create mode 100644 lib/routes/paidai/index.js create mode 100644 lib/routes/paidai/news.js create mode 100644 lib/routes/paidai/utils.js diff --git a/docs/other.md b/docs/other.md index 6da0418ff3..2315bbb9e9 100644 --- a/docs/other.md +++ b/docs/other.md @@ -544,3 +544,9 @@ type 为 all 时,category 参数不支持 cost 和 free | games | software | shishiredian | xljt | fhdq | xljt | tech | other | + +## 派代 + + + + diff --git a/lib/router.js b/lib/router.js index df3a6eed7a..16a67e404c 100755 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/paidai/bbs.js b/lib/routes/paidai/bbs.js new file mode 100644 index 0000000000..991abc813e --- /dev/null +++ b/lib/routes/paidai/bbs.js @@ -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, + }; +}; diff --git a/lib/routes/paidai/index.js b/lib/routes/paidai/index.js new file mode 100644 index 0000000000..512be19e31 --- /dev/null +++ b/lib/routes/paidai/index.js @@ -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, + }; +}; diff --git a/lib/routes/paidai/news.js b/lib/routes/paidai/news.js new file mode 100644 index 0000000000..97f0f40f0c --- /dev/null +++ b/lib/routes/paidai/news.js @@ -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, + }; +}; diff --git a/lib/routes/paidai/utils.js b/lib/routes/paidai/utils.js new file mode 100644 index 0000000000..21e2531480 --- /dev/null +++ b/lib/routes/paidai/utils.js @@ -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, +};