feat: add 什么值得买用户爆料 (#5155)

This commit is contained in:
Ethan Shen 2020-07-09 10:53:56 +08:00 committed by GitHub
parent 8efdffa781
commit 70d2d6332b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 0 deletions

View File

@ -185,6 +185,10 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
<Route author="xfangbao" example="/smzdm/article/6902738986" path="/smzdm/article/:uid" :paramsDesc="['用户id网址上直接可以看到']"/>
### 用户爆料
<Route author="nczitzk" example="/smzdm/baoliao/7367111021" path="/smzdm/baoliao/:uid" :paramsDesc="['用户id网址上直接可以看到']"/>
## 淘宝众筹
### 众筹项目

View File

@ -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'));

View File

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