we dont need much of the escaping magic cause for whatever crazy reason

this CSV format does not allow newlines
This commit is contained in:
Sam 2015-03-20 16:49:58 +11:00
parent 640a92ce30
commit c5dd11f64c

View file

@ -35,8 +35,8 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
super super
end end
def execute
def execute
c = Category.find_by(name: 'Old Forum') || c = Category.find_by(name: 'Old Forum') ||
Category.create!(name: 'Old Forum', user: Discourse.system_user) Category.create!(name: 'Old Forum', user: Discourse.system_user)
@ -83,19 +83,11 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
File.open(filename).each_line do |line| File.open(filename).each_line do |line|
# escaping is mental here
line.gsub!(/\\(.{1})/){|m| m[-1] == '"'? '""': m[-1]}
line.strip! line.strip!
current_row << "\n" unless current_row.empty? current_row << "\n" unless current_row.empty?
current_row << line current_row << line
double_quote_count += line.scan('"').count
if double_quote_count % 2 == 1
next
end
raw = begin raw = begin
CSV.parse(current_row, col_sep: ";") CSV.parse(current_row, col_sep: ";")
rescue CSV::MalformedCSVError => e rescue CSV::MalformedCSVError => e
@ -110,6 +102,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
current_row = "" current_row = ""
double_quote_count = 0 double_quote_count = 0
next next
end[0] end[0]