Merge pull request #74 from TrueTechy/bug/unicode-support#65

Update file handling to support unicode
This commit is contained in:
mcarlton00 2019-09-18 21:23:40 -04:00 committed by GitHub
commit 7e889f4561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import logging
import json
import os
import sqlite3
from io import open
import xbmc
import xbmcvfs
@ -354,7 +355,8 @@ def save_sync(sync):
sync['Date'] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
with open(os.path.join(path, 'sync.json'), 'w') as outfile:
json.dump(sync, outfile, sort_keys=True, indent=4, ensure_ascii=False)
data = json.dumps(sync, sort_keys=True, indent=4, ensure_ascii=False)
outfile.write(unicode(data))
def get_credentials():
@ -364,7 +366,7 @@ def get_credentials():
xbmcvfs.mkdirs(path)
try:
with open(os.path.join(path, 'data.json')) as infile:
with open(os.path.join(path, 'data.json'), encoding='utf8') as infile:
credentials = json.load(infile)
except Exception:
@ -387,9 +389,12 @@ def save_credentials(credentials):
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
with open(os.path.join(path, 'data.json'), 'w') as outfile:
json.dump(credentials, outfile, sort_keys=True, indent=4, ensure_ascii=False)
try:
with open(os.path.join(path, 'data.json'), 'w', encoding='utf8') as outfile:
data = json.dumps(credentials, sort_keys=True, indent=4, ensure_ascii=False)
outfile.write(unicode(data))
except Exception as e:
LOG.error("Failed to save credentials: {}".format(e))
def get_item(kodi_id, media):
@ -404,3 +409,4 @@ def get_item(kodi_id, media):
return
return item