Authored by 陈峰

comit

1 const fs = require('fs'); 1 const fs = require('fs');
2 -const nodeLockup = require('node-lockup');  
3 -const spider = require('../libs/spider');  
4 const readline = require('readline'); 2 const readline = require('readline');
5 const dayjs = require('dayjs'); 3 const dayjs = require('dayjs');
6 const _ = require('lodash'); 4 const _ = require('lodash');
@@ -15,19 +13,6 @@ const rl = readline.createInterface({ @@ -15,19 +13,6 @@ const rl = readline.createInterface({
15 input: fr 13 input: fr
16 }); 14 });
17 15
18 -const task = async(product) => {  
19 - console.log(product.productId);  
20 - const result = await spider.spiderFetch(product.productId);  
21 -  
22 - if (result.status === 200) {  
23 - if (result.data.detail.brandId !== 4981 && result.data.detail.brandId !== 10065) {  
24 - return product;  
25 - }  
26 - }  
27 -};  
28 -  
29 -const taskLock = nodeLockup(task);  
30 -  
31 16
32 const allProducts = []; 17 const allProducts = [];
33 18
@@ -36,11 +21,10 @@ rl.on('line', line => { @@ -36,11 +21,10 @@ rl.on('line', line => {
36 }); 21 });
37 22
38 rl.on('close', async() => { 23 rl.on('close', async() => {
39 - const takes = _.take(_.orderBy(allProducts, 'soldNum', 'desc'), 400);  
40 - const matchProducts = await Promise.all(takes.map(p => taskLock(p))); 24 + const takes = _.take(_.orderBy(allProducts.filter(p => p.brandId !== 4981 && p.brandId !== 10065), 'soldNum', 'desc'), 300);
41 25
42 console.log('duid,sales,model,price'); 26 console.log('duid,sales,model,price');
43 - _.take(matchProducts.filter(p => p), 300).forEach(product => { 27 + takes.forEach(product => {
44 console.log(`${product.productId},${product.soldNum},${product.articleNumber},${parseInt(product.price / 100, 10)}`); 28 console.log(`${product.productId},${product.soldNum},${product.articleNumber},${parseInt(product.price / 100, 10)}`);
45 }); 29 });
46 }); 30 });