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, +};