1
0

use explicit utf-8 encoding when opening files in text mode

This commit is contained in:
SomberNight
2018-03-23 21:47:51 +01:00
parent 382f69edd9
commit 9b7536e75c
11 changed files with 25 additions and 25 deletions

View File

@@ -66,7 +66,7 @@ class ExchangeBase(PrintError):
if os.path.exists(filename):
timestamp = os.stat(filename).st_mtime
try:
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8') as f:
h = json.loads(f.read())
h['timestamp'] = timestamp
except:
@@ -87,7 +87,7 @@ class ExchangeBase(PrintError):
self.print_error("failed fx history:", e)
return
filename = os.path.join(cache_dir, self.name() + '_' + ccy)
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf-8') as f:
f.write(json.dumps(h))
h['timestamp'] = time.time()
self.history[ccy] = h
@@ -382,7 +382,7 @@ def get_exchanges_and_currencies():
import os, json
path = os.path.join(os.path.dirname(__file__), 'currencies.json')
try:
with open(path, 'r') as f:
with open(path, 'r', encoding='utf-8') as f:
return json.loads(f.read())
except:
pass
@@ -399,7 +399,7 @@ def get_exchanges_and_currencies():
except:
print(name, "error")
continue
with open(path, 'w') as f:
with open(path, 'w', encoding='utf-8') as f:
f.write(json.dumps(d, indent=4, sort_keys=True))
return d