Fix the issue of lacking the chardet module

Former-commit-id: 73fa567e2ccbfed26983d8d21caae38fd48b4bfa
This commit is contained in:
Physton
2023-05-17 15:33:46 +08:00
parent 316603e4cf
commit 00f40d0674

View File

@@ -2,7 +2,7 @@ import os
from pathlib import Path
import json
import time
import chardet
import launch
class storage:
storage_path = ''
@@ -53,15 +53,18 @@ class storage:
if not os.path.exists(filename):
return None
try:
with open(filename, 'rb') as f:
data = f.read()
encoding = chardet.detect(data).get('encoding')
data = json.loads(data.decode(encoding))
if not launch.is_installed("chardet"):
with open(filename, 'r') as f:
data = json.load(f)
else:
import chardet
with open(filename, 'rb') as f:
data = f.read()
encoding = chardet.detect(data).get('encoding')
data = json.loads(data.decode(encoding))
except Exception as e:
print(e)
return None
# with open(filename, 'r') as f:
# data = json.load(f)
return data
def __set(self, key, data):