Created
November 26, 2014 06:40
-
-
Save evilpacket/0c2e16d22f2353a0b2e1 to your computer and use it in GitHub Desktop.
Convert data.sparkfun.com csv to format that charted.co doesn't hate
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
var csv = require('csv'); | |
var request = require('request'); | |
var Hapi = require('hapi'); | |
var server = new Hapi.Server(); | |
server.connection({ port: 4000, labels: 'a' }); | |
var url = "https://data.sparkfun.com/output/XXXXXXXXX.csv"; | |
server.route({ | |
method: 'GET', | |
path: '/csv', | |
handler: function (req, reply) { | |
reply(request.get(url) | |
.pipe(csv.parse()) | |
.pipe(csv.transform(function(record){ | |
return [record[2], record[1], record[0]]; | |
})) | |
.pipe(csv.stringify())) | |
} | |
}); | |
server.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment