Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created June 20, 2019 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisonmalone/77bd3219d66cad3cc0e4fa0c50cef1cf to your computer and use it in GitHub Desktop.
Save harrisonmalone/77bd3219d66cad3cc0e4fa0c50cef1cf to your computer and use it in GitHub Desktop.
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