
Untitled
By: a guest on
Aug 6th, 2012 | syntax:
None | size: 0.66 KB | hits: 11 | expires: Never
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