From a4147bbf11af87703e63d7f24ddb094063a1861d Mon Sep 17 00:00:00 2001 From: Bruno Ilponse Date: Tue, 30 Oct 2018 08:50:18 +0100 Subject: [PATCH 1/2] fixed bug preventing the delimiter to be changed --- es2csv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/es2csv.py b/es2csv.py index 054d1ec..e393236 100755 --- a/es2csv.py +++ b/es2csv.py @@ -209,7 +209,8 @@ def write_to_csv(self): self.num_results = sum(1 for line in codecs.open(self.tmp_file, mode='r', encoding='utf-8')) if self.num_results > 0: output_file = codecs.open(self.opts.output_file, mode='a', encoding='utf-8') - csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers) + delimiter = self.opts.delimiter.decode('utf-8') if self.opts.delimiter else ',' + csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=delimiter) csv_writer.writeheader() timer = 0 widgets = ['Write to csv ', From 7a0f6d3fad32906d1743cc9fb961a1509d4b7c8b Mon Sep 17 00:00:00 2001 From: Bruno Ilponse Date: Tue, 30 Oct 2018 14:28:56 +0100 Subject: [PATCH 2/2] Added a BOM to let know applications that the file is in UTF-8 encoding --- es2csv.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/es2csv.py b/es2csv.py index e393236..978f9c3 100755 --- a/es2csv.py +++ b/es2csv.py @@ -208,6 +208,10 @@ def write_to_csv(self): if self.num_results > 0: self.num_results = sum(1 for line in codecs.open(self.tmp_file, mode='r', encoding='utf-8')) if self.num_results > 0: + output_file = codecs.open(self.opts.output_file, mode='a') + output_file.write(codecs.BOM_UTF8) + output_file.close() + output_file = codecs.open(self.opts.output_file, mode='a', encoding='utf-8') delimiter = self.opts.delimiter.decode('utf-8') if self.opts.delimiter else ',' csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=delimiter)