Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'rubygems'
  2. require 'faster_csv'
  3. require 'net/http'
  4. require 'open-uri'
  5.  
  6. class String
  7.   require 'iconv' #this line is not needed in rails !
  8.   def to_utf8
  9.     Iconv.conv('utf-8','ISO-8859-1', self)
  10.   end
  11. end
  12.  
  13.  
  14. puts "opening remote csv file"
  15. handle = open(URI.parse("http://coverinfo.de/download/datenbank.csv"))
  16. puts "beginning to convert"
  17. rows = []
  18.  
  19. FasterCSV.parse(handle, :skip_blanks => true, :col_sep => ";", :quote_char => "~") do |row|
  20.   rows << row.map {|r| r.to_utf8 if r}
  21. end
  22.  
  23. #drop first line
  24. rows.shift
  25.  
  26. FasterCSV.open(File.join(File.expand_path("~"), "clean_cover2.csv"), "w", :col_sep => ",", :quote_char => '"') do |new_row|
  27.   rows.each {|r| new_row << r}
  28. end