Authored by 杨延青

Merge branch 'feature/detailApi' into 'master'

change du api



See merge request !17
... ... @@ -4,6 +4,9 @@ const nodeLockup = require('node-lockup');
const chalk = require('chalk');
const {logger} = require('./logger');
const detailUrl = 'https://app.poizon.com/api/v1/h5/index/fire/flow/product/detail';
const sign = (obj) => {
let constr = '';
... ... @@ -25,8 +28,8 @@ const task = async(options, tick = 1) => {
json: true,
headers: {
Accept: 'application/json, text/plain, */*',
appVersion: '3.5.0',
Referer: 'http://du.hupu.com/mdu/product/detail.html?id=1&source=boutiqueRecommend',
appVersion: '4.4.0',
Referer: 'https://m.poizon.com/mdu/product/detail.html?id=1&source=shareDetail',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 Safari/604.1',
'X-Requested-With': 'XMLHttpRequest'
},
... ... @@ -43,20 +46,20 @@ const task = async(options, tick = 1) => {
}
};
module.exports = (ids, url = 'http://du.hupu.com/mapi/product/detail', params, delay) => {
module.exports = (ids, url, params, delay) => {
const lockTask = nodeLockup(task, delay || 1);
return ids.map(id => lockTask(Object.assign({
productId: id,
source: 'boutiqueRecommend',
url
productSourceName: 'shareDetail',
url: url || detailUrl
}, params)));
};
module.exports.spiderFetch = (id, url = 'http://du.hupu.com/mapi/product/detail', params) => {
module.exports.spiderFetch = (id, url, params) => {
return task(Object.assign({
productId: id,
source: 'boutiqueRecommend',
url
productSourceName: 'shareDetail',
url: url || detailUrl
}, params));
};
... ...
... ... @@ -6,6 +6,8 @@ const {logger} = require('./logger');
const config = require('../config/index');
const detailUrl = 'https://app.poizon.com/api/v1/h5/index/fire/flow/product/detail';
const sign = (obj) => {
let constr = '';
... ... @@ -27,8 +29,8 @@ const task = async(options, tick = 1) => {
json: true,
headers: {
Accept: 'application/json, text/plain, */*',
appVersion: '3.5.0',
Referer: 'http://du.hupu.com/mdu/product/detail.html?id=1&source=boutiqueRecommend',
appVersion: '4.4.0',
Referer: 'https://m.poizon.com/mdu/product/detail.html?id=1&source=shareDetail',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 Safari/604.1',
'X-Requested-With': 'XMLHttpRequest'
},
... ... @@ -45,20 +47,20 @@ const task = async(options, tick = 1) => {
}
};
module.exports = (ids, url = 'http://du.hupu.com/mapi/product/detail', params, delay) => {
module.exports = (ids, url, params, delay) => {
const lockTask = nodeLockup(task, delay || config.delay);
return ids.map(id => lockTask(Object.assign({
productId: id,
source: 'boutiqueRecommend',
url
productSourceName: 'shareDetail',
url: url || detailUrl
}, params)));
};
module.exports.spiderFetch = (id, url = 'http://du.hupu.com/mapi/product/detail', params) => {
module.exports.spiderFetch = (id, url, params) => {
return task(Object.assign({
productId: id,
source: 'boutiqueRecommend',
url
productSourceName: 'shareDetail',
url: url || detailUrl
}, params));
};
... ...
... ... @@ -2,7 +2,7 @@ const spider = require('../libs/spider');
const _ = require('lodash');
const spiderTask = async ids => {
spider(ids, 'http://du.hupu.com/mapi/product/detail', {}, 1).forEach(promise => promise.then(result => {
spider(ids, '', {}, 1).forEach(promise => promise.then(result => {
if (result.status === 200) {
const sizes = result.data.sizeList;
... ...
... ... @@ -51,7 +51,7 @@ const lockReportTask = nodeLockup(report);
function spiderData(products) {
const ids = products.map(p => p.duId);
return spider(ids, 'http://du.hupu.com/mapi/product/detail', {}, 1).forEach(promise => promise.then(result => {
return spider(ids, '', {}, 1).forEach(promise => promise.then(result => {
if (result && result.status === 200) {
const {detail} = result.data;
const find = _.find(products, p => p.duId === detail.productId);
... ...
... ... @@ -24,7 +24,7 @@ module.exports = async(time) => {
const allProducts = await ProductRelationModel.findAll();
const duProducts = allProducts.filter(p => _.has(p, 'third.du.productId'));
spider(duProducts.map(p => _.get(p, 'third.du.productId')), 'http://du.hupu.com/mapi/product/detail', {}, 1)
spider(duProducts.map(p => _.get(p, 'third.du.productId')), '', {}, 1)
.forEach(promise => promise.then(result => {
if (result.status !== 200 && !_.has(result, 'data.detail')) {
logger.warn(`[spider-task]爬取失败记录: ${JSON.stringify(result)}`);
... ...
... ... @@ -46,7 +46,7 @@ module.exports = async(time) => {
// });
// }
spider(sknsData.map(p => p.productId), 'http://du.hupu.com/mapi/product/detail', {}, 1)
spider(sknsData.map(p => p.productId), '', {}, 1)
.forEach(promise => promise.then(result => {
if (result.status !== 200 && !_.has(result, 'data.detail')) {
logger.warn(`[spider-task]爬取失败记录: ${JSON.stringify(result)}`);
... ...