mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
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:
parent
640a92ce30
commit
c5dd11f64c
1 changed files with 2 additions and 9 deletions
|
@ -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]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue