Thursday 26 March 2020

Help with parsing CSV to ICS

I come to you in dire need. I've been trying to parse the csv file to ics for a few days now and got really stuck at one point, It parses it alright but at the end of the file in ics it displays only the last one. So i need "element" to repeat as far as the csv rows go and parse into one event.ics. What am i doing wrong?const { writeFileSync } = require('fs') const ics = require('ics') const fs = require('fs') const fastCsv = require('fast-csv') const csv = ('csv/example.csv') const moment = require('moment') fs.createReadStream(csv) .pipe(fastCsv.parse({ headers: false })) .on('data', (row) => { const [Anrufsart, Datum, Dauer, Nummer, Kontakt] = row let singleDatum = moment(Datum).format('YYYY'); let singleMonth = moment(Datum).format('M'); let singleDay = moment(Datum).format('D'); let hours = moment(Datum).format('HH'); let mins = moment(Datum).format('mm'); const icsArray = []; for (let i = 0; i < row.length; i++) { const element = { summary:Anrufsart, title: Kontakt, start: [parseInt(singleDatum), parseInt(singleMonth), parseInt(singleDay), parseInt(hours), parseInt(mins)], duration: { minutes: parseInt(Dauer)}, description:Nummer } icsArray.push(element) } const { error, value } = ics.createEvents(icsArray) if (error) { console.log(error) return } setTimeout(() => { writeFileSync(`${__dirname}/event.ics`, value) }, 2000); })

Submitted March 26, 2020 at 01:44PM by markoza94

No comments:

Post a Comment