export.js 821 Bytes
const fs = require('fs');
const readline = require('readline');
const dayjs = require('dayjs');
const _ = require('lodash');
const date = process.argv[2];

const fileName = date ? date.match(/--d=(.*)/)[1] : dayjs().format('YYYY-MM-DD');

const fr = fs.createReadStream(`/Data/logs/node/prices/${fileName}.log`);


const rl = readline.createInterface({
  input: fr
});


const allProducts = [];

rl.on('line', line => {
  allProducts.push(JSON.parse(line));
});

rl.on('close', async() => {
  const takes = _.take(_.orderBy(allProducts.filter(p => p.brandId !== 4981 && p.brandId !== 10065), 'soldNum', 'desc'), 300);

  console.log('duid,sales,model,price');
  takes.forEach(product => {
    console.log(`${product.productId},${product.soldNum},${product.articleNumber},${parseInt(product.price / 100, 10)}`);
  });
});