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
1 changed files with 2 additions and 9 deletions

View File

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