NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const fs = require('fs');
const csvFilePath = './src/app/database/csv-parser/offers.csv';
const csv = require('csvtojson');
const cataloguePrices = require('../catalogue-prices.json');

const priceRanges = [
{min: 0, max: 20},
{min: 20, max: 30},
{min: 30, max: 40},
{min: 40, max: 50},
{min: 50, max: 60},
{min: 60, max: 70},
{min: 70, max: 80},
{min: 80, max: 90},
{min: 90, max: 100},
{min: 100, max: 120},
{min: 120, max: 130},
{min: 130, max: 140},
{min: 140, max: 150},
{min: 150, max: 170},
{min: 170, max: 200},
{min: 200, max: Number.POSITIVE_INFINITY},
];

const changeTagNames = tag => {

const mbIndex = tag.indexOf('Mb');

if (mbIndex !== -1) {
if (tag[mbIndex - 1] !== ' ') {
return tag.slice(0, mbIndex) + ' ' + tag.slice(mbIndex);
}
return tag;
}

const key = tag.toUpperCase();
const nameMap = {
'BEZLIMIT UE 6GB': 'BEZLIMIT UE 6 GB',
'BEZ LIMIT UE 6 GB': 'BEZLIMIT UE 6 GB',
'BEZ LIMIT UE 12 GB': 'BEZLIMIT UE 12 GB',
'BEZ LIMIT UE 17 GB': 'BEZLIMIT UE 17 GB',
'PLATYNA': 'Platynowy',
'DOMOWY HALO3 24': 'Domowy Halo 24',
'DOMOWY HALO3 36': 'Domowy Halo 36',
'OSTRY (SNO+ERO)': 'Ostry (SnO+Ero)',
'FILM GO': 'Film GO',
'0': 'brak',
'BI (2PC)': 'F-Secure (2 urządzenia)',
'BEZPIECZNY INTERNET (2)': 'F-Secure (2 urządzenia)',
'5GB': '5 GB',
'BEZ LIMIT 5GB': 'BEZLIMIT 5GB',
'BEZ LIMIT 11GB': 'BEZLIMIT 11GB',
'BEZ LIMIT 16GB': 'BEZLIMIT 16GB',
'KUPONO VOD': 'svod Dziecięcy',
'VODUSIE': 'svod Dziecięcy',
'SNO': 'SNO',
'SPORT NA OSTRO': 'SNO',
'CANAL+ SELECT': 'C+Select',
'CANAL+SELECT': 'C+Select',
'CANAL+ PRESTIGE': 'C+Prestige',
'CANAL+PRESTIGE': 'C+Prestige',
'SUPERFILM&SPORT': 'Super F&S',
'DOMOWY BEZ LIMITU': 'DBL',
'DOMOWY 250': 'D250',
'DOMOWY 100': 'D100',
'DOMOWY 50': 'D50',
};
return nameMap[key] ? nameMap[key] : tag;
};


const getNumber = (number) => {
for (const index in number) {
if (number[index] === ',') {
number = number.substring(0, index) + '.' + number.substring(Number(index) + 1);
}
}
if (typeof number !== 'number') {
number = Number(number);
}
return number;
};

const checkIfIndexOf = (key, words) => words.some(word => key.indexOf(word) !== -1);
const offers = {offers: []};
csv({delimiter: ','})
.fromFile(csvFilePath)
.on('json', (offerCsv, index) => {

const offer = {
discounts: [],
prices: [],
tags: [],
id: index
};
if (offerCsv['name'] !== '') {
Object.keys(offerCsv).forEach(key => {
offerCsv[key] = offerCsv[key].toString().trim();
offerCsv[key] = changeTagNames(offerCsv[key]);
offer[key] = offerCsv[key];
if (key.indexOf('Discount') !== -1 && offerCsv[key]) {

const obj = {};
const newKey = key.replace('Discount', '');
const discount = getNumber(offerCsv[key]);

if (checkIfIndexOf(key, ['premium', 'extra'])) {
const premium = offerCsv[newKey];
obj[premium] = discount;
} else {
obj[newKey] = discount;
}
offer['discounts'].push(obj);
} else if (checkIfIndexOf(key, ['premium', 'extra', 'telephone', 'tv', 'decoder', 'internet', 'mobile', 'mobileInternet', 'range', 'period']) && offerCsv[key] && key.indexOf('Price') === -1) {
let tag;
if (key.indexOf('premium') !== -1) {
tag = 'premium';
} else if (key.indexOf('extra') !== -1) {
tag = 'extra';
}
if (!checkIfIndexOf(key, ['range', 'period'])) {
let price = offerCsv[`${key}Price`] || '';
price = getNumber(price);
const name = [offerCsv[key]][0];
const cataloguePrice = cataloguePrices[name] || '';
const priceObject = {
name: [offerCsv[key]][0],
price: Number(price),
cataloguePrice: cataloguePrice,
premium: tag === 'premium'
};
offer.prices.push(priceObject);
}
offer.tags.push({'value': offerCsv[key], 'type': tag || key})
} else if (checkIfIndexOf(key, ['name', 'startDate', 'expirationDate', 'contractDuration', 'priceAfterContractExpiration', 'activationPrice', 'comarchId', 'regulations', 'comments'])) {
offerCsv[key] === 'brak' ? offer[key] = 0 : offer[key] = offerCsv[key];
} else if (key === 'price') {
let price = offerCsv[key];
price = getNumber(price);
offer[key] = Math.round(Number(price) * 100) / 100;
const priceRangeObject = priceRanges.find(priceRange => {
return Number(price) >= priceRange.min && price < priceRange.max;
});
try {
const priceRange = `${priceRangeObject.min}-${priceRangeObject.max}`;
offer.tags.push({'type': 'price', 'value': priceRange})
}
catch (err) {
}
} else if (key === 'cities') {
offer[key] = offerCsv[key].split(',').map(city => city.trim());
}
});
if (!offer.comarchId) {
console.log(offerCsv)
}
offers.offers.push(offer);
}

})
.on('done', (error) => {
fs.writeFile("./src/app/database/offers.json", JSON.stringify(offers), function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
});





     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.