Authored by 陈峰

comit

const fs = require('fs');
const nodeLockup = require('node-lockup');
const spider = require('../libs/spider');
const readline = require('readline');
const dayjs = require('dayjs');
const _ = require('lodash');
... ... @@ -15,19 +13,6 @@ const rl = readline.createInterface({
input: fr
});
const task = async(product) => {
console.log(product.productId);
const result = await spider.spiderFetch(product.productId);
if (result.status === 200) {
if (result.data.detail.brandId !== 4981 && result.data.detail.brandId !== 10065) {
return product;
}
}
};
const taskLock = nodeLockup(task);
const allProducts = [];
... ... @@ -36,11 +21,10 @@ rl.on('line', line => {
});
rl.on('close', async() => {
const takes = _.take(_.orderBy(allProducts, 'soldNum', 'desc'), 400);
const matchProducts = await Promise.all(takes.map(p => taskLock(p)));
const takes = _.take(_.orderBy(allProducts.filter(p => p.brandId !== 4981 && p.brandId !== 10065), 'soldNum', 'desc'), 300);
console.log('duid,sales,model,price');
_.take(matchProducts.filter(p => p), 300).forEach(product => {
takes.forEach(product => {
console.log(`${product.productId},${product.soldNum},${product.articleNumber},${parseInt(product.price / 100, 10)}`);
});
});
... ...