Created
November 29, 2012 14:18
-
-
Save toto/4169387 to your computer and use it in GitHub Desktop.
Convert VBB Station CSV to simple JSON array. CSV source: https://raw.github.com/okfde/appsandthecity/gh-pages/downloads/VBB_Haltestellen_Entwicklertag.csv
This file contains hidden or 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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# | |
# Usage: ruby csv2json.rb filename.csv | |
# | |
require 'csv' | |
require 'pp' | |
require 'json' | |
filename = File.expand_path(ARGV.last) | |
if File.exist?(filename) | |
data = [] | |
csv = CSV.new(File.read(filename).force_encoding("ISO-8859-1"), headers: true, col_sep: ";") | |
csv.each do |row| | |
data << {"vbb_id" => row["VBB-Nr"].to_s, | |
"hafas_id" => row["HAFAS-Nr"].to_s, | |
"name" => row["NAME"].to_s, | |
"lat" => row["lat"].to_f, | |
"lon" => row["lon"].to_f} | |
end | |
puts JSON.pretty_generate(data) | |
else | |
raise "No CSV file at #{filename}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment