mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Update export json and csv for Python 2
This commit is contained in:
parent
ed454b2a4a
commit
6fb3a3a3c8
2 changed files with 8 additions and 17 deletions
|
@ -17,8 +17,8 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
from future.builtins import str
|
||||
from backports import csv
|
||||
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
|
@ -941,23 +941,14 @@ def _real_export(export_id, items, attrs, file_format, filename):
|
|||
result = pool.map(part, items)
|
||||
|
||||
if file_format == 'json':
|
||||
if plexpy.PYTHON2:
|
||||
kw = {'mode': 'wb'}
|
||||
else:
|
||||
kw = {'mode': 'w', 'encoding': 'utf-8'}
|
||||
|
||||
with open(filepath, **kw) as outfile:
|
||||
json.dump(result, outfile, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
json_data = json.dumps(result, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
with open(filepath, 'w', encoding='utf-8') as outfile:
|
||||
outfile.write(json_data)
|
||||
|
||||
elif file_format == 'csv':
|
||||
if plexpy.PYTHON2:
|
||||
kw = {'mode': 'wb'}
|
||||
else:
|
||||
kw = {'mode': 'w', 'encoding': 'utf-8', 'newline': ''}
|
||||
|
||||
flatten_result = helpers.flatten_dict(result)
|
||||
flatten_attrs = set().union(*flatten_result)
|
||||
with open(filepath, **kw) as outfile:
|
||||
with open(filepath, 'w', encoding='utf-8', newline='') as outfile:
|
||||
writer = csv.DictWriter(outfile, sorted(flatten_attrs))
|
||||
writer.writeheader()
|
||||
writer.writerows(flatten_result)
|
||||
|
|
|
@ -19,10 +19,10 @@ from __future__ import unicode_literals
|
|||
from future.builtins import next
|
||||
from future.builtins import object
|
||||
from future.builtins import str
|
||||
from backports import csv
|
||||
|
||||
from io import open
|
||||
import base64
|
||||
import csv
|
||||
import json
|
||||
import linecache
|
||||
import os
|
||||
|
@ -6538,8 +6538,8 @@ class WebInterface(object):
|
|||
return serve_file(exporter.get_export_filepath(result['filename']), name=result['filename'],
|
||||
content_type='application/json')
|
||||
elif result['file_format'] == 'csv':
|
||||
with open(exporter.get_export_filepath(result['filename']), 'r', encoding='utf-8') as f:
|
||||
reader = csv.DictReader(f)
|
||||
with open(exporter.get_export_filepath(result['filename']), 'r', encoding='utf-8') as infile:
|
||||
reader = csv.DictReader(infile)
|
||||
table = '<table><tr><th>' + \
|
||||
'</th><th>'.join(reader.fieldnames) + \
|
||||
'</th></tr><tr>' + \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue