From 70d2d6332bbcc8adb32bd0d17753f827f8a0897d Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 9 Jul 2020 10:53:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=BB=80=E4=B9=88=E5=80=BC?= =?UTF-8?q?=E5=BE=97=E4=B9=B0=E7=94=A8=E6=88=B7=E7=88=86=E6=96=99=20(#5155?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/shopping.md | 4 +++ lib/router.js | 1 + lib/routes/smzdm/baoliao.js | 56 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/routes/smzdm/baoliao.js diff --git a/docs/shopping.md b/docs/shopping.md index ca75e19f0..093834e47 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -185,6 +185,10 @@ For instance, in +### 用户爆料 + + + ## 淘宝众筹 ### 众筹项目 diff --git a/lib/router.js b/lib/router.js index 684c9457b..fa8c4960e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -320,6 +320,7 @@ router.get('/smzdm/ranking/:rank_type/:rank_id/:hour', require('./routes/smzdm/r router.get('/smzdm/haowen/:day?', require('./routes/smzdm/haowen')); router.get('/smzdm/haowen/fenlei/:name/:sort?', require('./routes/smzdm/haowen_fenlei')); router.get('/smzdm/article/:uid', require('./routes/smzdm/article')); +router.get('/smzdm/baoliao/:uid', require('./routes/smzdm/baoliao')); // 新京报 router.get('/bjnews/:cat', require('./routes/bjnews/news')); diff --git a/lib/routes/smzdm/baoliao.js b/lib/routes/smzdm/baoliao.js new file mode 100644 index 000000000..142181df2 --- /dev/null +++ b/lib/routes/smzdm/baoliao.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); + +module.exports = async (ctx) => { + const link = `https://zhiyou.smzdm.com/member/${ctx.params.uid}/baoliao/`; + + const response = await got.get(link); + const $ = cheerio.load(response.data); + const title = $('.info-stuff-nickname').text(); + + const list = $('.pandect-content-stuff') + .slice(0, 20) + .map(function () { + const info = { + title: $(this).find('.pandect-content-title a').text(), + link: $(this).find('.pandect-content-title a').attr('href'), + pubdate: $(this).find('.pandect-content-time').text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const pubdate = info.pubdate; + const itemUrl = info.link; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got.get(itemUrl); + const $ = cheerio.load(response.data); + const content = $('article.txt-detail'); + const description = content.html(); + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: date(pubdate), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${title}的爆料 - 什么值得买`, + link: link, + item: out, + }; +};