Skip to content

Instantly share code, notes, and snippets.

@chadfurman
Created March 29, 2020 07:19
Show Gist options
  • Save chadfurman/e68d673c1071ba49b06d41a259b56da9 to your computer and use it in GitHub Desktop.
Save chadfurman/e68d673c1071ba49b06d41a259b56da9 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const csv = require('fast-csv');
fs.createReadStream(path.resolve(__dirname, 'COVID-19/csse_covid_19_data/csse_covid_19_daily_reports/', '03-28-2020.csv'))
.pipe(csv.parse({ headers: true }))
.on('error', error => console.error(error))
.on('data', row => {
const data = {}
data.province = row['Province_State'] || row['Province/State']
data.region = row['Country_Region'] || row['Country/Region']
data.locality = row['Admin2']
data.lat = row['Lat'] || row['Latitude']
data.long = row['Long_'] || row['Longitude']
data.confirmed = row['Confirmed']
data.deaths = row['Deaths']
data.recoveries = row['Recovered']
// TODO: look up locality ID and create if not found, returning the ID
// TODO: look up province ID and create if not found, returning the ID
// TODO: look up region ID and create if not found, returning the ID
// TODO: create location record
// TODO: create CONFIRMED cases record
// TODO: create DEATHS cases record
// TODO: create RECOVERED cases record
})
.on('end', rowCount => console.log(`Parsed ${rowCount} rows`));
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment