export.js 643 Bytes
const fs = require('fs');
const readline = require('readline');
const dayjs = require('dayjs');
const _ = require('lodash');

const fr = fs.createReadStream(`/Data/logs/node/prices/${dayjs().format('YYYY-MM-DD')}.log`);


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


console.log('duid,sales,model,price');

const allProducts = [];

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

rl.on('close', () => {
  _.take(_.orderBy(allProducts, 'soldNum', 'desc'), 300).forEach(product => {
    console.log(`${product.productId},${product.soldNum},${product.articleNumber},${parseInt(product.price / 100, 10)}`);
  });
});