From e4644a365585a7d58969ce912fb119e020e23b71 Mon Sep 17 00:00:00 2001 From: Artem Tomyuk Date: Wed, 26 Jul 2017 12:14:03 +0300 Subject: [PATCH 1/2] for python3 support --- es2csv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es2csv.py b/es2csv.py index b948843..11e4f25 100755 --- a/es2csv.py +++ b/es2csv.py @@ -234,7 +234,7 @@ def write_to_csv(self): timer += 1 bar.update(timer) line_as_dict = json.loads(line) - line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, unicode) else v for k, v in line_as_dict.items()} + line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, str) else v for k, v in line_as_dict.items()} csv_writer.writerow(line_dict_utf8) output_file.close() bar.finish() From 489d3ac5c2ca00adaffa570ee03c24ccf81ce984 Mon Sep 17 00:00:00 2001 From: Artem Tomyuk Date: Mon, 31 Jul 2017 18:20:12 +0300 Subject: [PATCH 2/2] convert to string either to byte --- es2csv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/es2csv.py b/es2csv.py index 11e4f25..48cd446 100755 --- a/es2csv.py +++ b/es2csv.py @@ -216,7 +216,7 @@ def write_to_csv(self): if self.num_results > 0: self.num_results = sum(1 for line in open(self.tmp_file, 'r')) if self.num_results > 0: - output_file = open(self.opts.output_file, 'a') + output_file = open(self.opts.output_file, 'a', encoding='utf-8') csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=self.opts.delimiter) csv_writer.writeheader() timer = 0 @@ -234,7 +234,7 @@ def write_to_csv(self): timer += 1 bar.update(timer) line_as_dict = json.loads(line) - line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, str) else v for k, v in line_as_dict.items()} + line_dict_utf8 = {k: v if isinstance(v, str) else v for k, v in line_as_dict.items()} csv_writer.writerow(line_dict_utf8) output_file.close() bar.finish()