Created
June 20, 2019 00:41
-
-
Save harrisonmalone/77bd3219d66cad3cc0e4fa0c50cef1cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const parse = require('csv-parse'); | |
const cleanData = (data) => { | |
data.splice(0, 1); | |
const result = { | |
rankings: [] | |
} | |
data.forEach((athlete) => { | |
let newAthlete = { | |
name: athlete[2], | |
gender: athlete[4], | |
time: athlete[6], | |
year: athlete[7] | |
} | |
result.rankings.push(newAthlete) | |
}) | |
return result | |
} | |
const data = fs.readFileSync('./tan_all_time.csv', 'utf-8') | |
parse(data, (err, output) => { | |
if (err) console.log(err) | |
const athletes = cleanData(output) | |
fs.writeFile('./tan_all_time.json', JSON.stringify(athletes, null, 2), (err) => { | |
if (err) console.log(err) | |
console.log('yayyyyy!!!!') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment