Skip to content

Instantly share code, notes, and snippets.

@ahnl
Created April 1, 2021 17:01
Show Gist options
  • Save ahnl/ce1382862e2894c574d7c783bbf22027 to your computer and use it in GitHub Desktop.
Save ahnl/ce1382862e2894c574d7c783bbf22027 to your computer and use it in GitHub Desktop.
Esimerkkiskripti THL koronatilastojen lukemisesta NodeJSällä
const axios = require("axios")
axios("https://sampo.thl.fi/pivot/prod/fi/epirapo/covid19case/fact_epirapo_covid19case.csv?row=508804L&column=measure-444833&fo=1")
.then(({data}) => {
// Pilko rivien mukaan arrayhin
data = data.split("\n")
// Poista ensimmäinen rivi, siinä ei ole dataa
data.shift()
data = data.map(row => {
// Pilko rivi sarakkeisiin puolipisteen mukaan
let columns = row.split(";")
// Palauta 2. ja 3. sarake
return {
date: columns[1],
count: columns[2]
}
})
console.log(data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment