Skip to content

Instantly share code, notes, and snippets.

Created March 14, 2012 14:13
Show Gist options
  • Save anonymous/2036741 to your computer and use it in GitHub Desktop.
Save anonymous/2036741 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'faster_csv'
require 'net/http'
require 'open-uri'
class String
require 'iconv' #this line is not needed in rails !
def to_utf8
Iconv.conv('utf-8','ISO-8859-1', self)
end
end
puts "opening remote csv file"
handle = open(URI.parse("http://coverinfo.de/download/datenbank.csv"))
puts "beginning to convert"
rows = []
FasterCSV.parse(handle, :skip_blanks => true, :col_sep => ";", :quote_char => "~") do |row|
rows << row.map {|r| r.to_utf8 if r}
end
#drop first line
rows.shift
FasterCSV.open(File.join(File.expand_path("~"), "clean_cover2.csv"), "w", :col_sep => ",", :quote_char => '"') do |new_row|
rows.each {|r| new_row << r}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment