0

I'm driving myself slight crazy with this one.

I am trying to import a CSV file:

uploaded_io = File.read("amazon_import.csv")
FasterCSV.parse(uploaded_io, {:headers => true, :quote_char => '"', :col_sep => "\t"}).each do |row_data|

  new_record = AmazonSale.new(
    'asin' => row[0],
    'title' => row[1],
    'barcode' => row[2].match(/\d+/),
    'price' => row[4],
    'discount' => row[5],
    'cost' => row[7],
    'active' => row[8],
    'product_group' => row[9],
    'release_date' => row[10],
    'customer_ordered_units' => row[11],
    'shipped_units' => row[12],
    'shipped_date' => Date.today - 1,
    'shipped_cogs' => row[14],
    'sellable_on_hand_units' => row[15],
    'unsellable_on_hand_units' => row[16],
    'customer_owned' => row[17],
    'total_inventory_units' => row[18],
    'vendor_units_received' => row[19],
    'open_po_qty' => row[20],
    'two_week_forecast' => "",
    'four_week_forecast' => "",
    'category' => "",
    'subcategory' => "",
    'author' => row[25],
    'binding' => "",
    'platform' => "",
    'cat_no' => row[28]
  )
  new_record.save
end

I use almost identical scripts elsewhere in my app successfully, but this one is throwing an error like:

FasterCSV::MalformedCSVError: Illegal quoting in line 70.

The offending line looks like:

0711297466621,£,5.56,20,£,4.45,Active,Music,06/10/2003,2,5,£,22.25,0,0,4,4,1,27,Alternative & Indie,Unknown,"Bragg, Billy",Audio CD,cd,COOKCD266,,

I can see it's "Bragg, Billy" causing this and have tried all kind of things to escape or remove the comma and quotes but I keep getting the same error.

Can anyone help?

I'm on Ruby 1.8.7.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Raoot
  • 1,751
  • 1
  • 25
  • 51
  • This is not an easy question as stated. What is the error when you try to replace the separator with ";" and use it as a separator for the parsing? – poseid May 14 '13 at 11:52
  • 1
    Is there a space after the comma and before the quoted name? – Kashyap May 14 '13 at 11:59
  • @poseid the error is the same – Raoot May 14 '13 at 12:37
  • @Kashyap - no space, it's exactly as you see above – Raoot May 14 '13 at 12:37
  • Ok, I think i've sussed this out - two stupid mistakes on my part that were confusing matters. @Kashyap you were almost right about the separator. I had it set for a tab, which is the format the file used to be in, but forgot to change to a comma when I change the file format to CSV. Also, my each do loop was outputting 'row_data' but I was calling 'row' within the loop. – Raoot May 14 '13 at 12:47

0 Answers0