Skip to content

Commit

Permalink
Fix errore file vuoto
Browse files Browse the repository at this point in the history
  • Loading branch information
MainKronos committed Sep 27, 2022
1 parent 4753e57 commit ce8e2f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
16 changes: 9 additions & 7 deletions config/utility/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def data(self) -> List[Dict]:
"""
Lista di dizionari contenente tutte le informazioni.
"""
if not os.path.exists(self.file):
self.write([])
return []


with open(self.file, 'r') as f:
return json.loads(f.read())
if os.path.exists(self.file) and os.path.getsize(self.file) > 0:
try:
with open(self.file, 'r') as f:
return json.loads(f.read())
except json.JSONDecodeError:
pass

self.write([])
return []

@classmethod
def toggle(self, connection_name:str):
Expand Down
22 changes: 14 additions & 8 deletions config/utility/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ def data(self) -> Dict[str,str]:

settings = {}

if os.path.exists(self.file):
with open(self.file, 'r') as f:
settings = json.loads(f.read())

for info in data:
if info not in settings:
settings[info] = data[info]
update_fix = True
if os.path.exists(self.file) and os.path.getsize(self.file) > 0:
try:
with open(self.file, 'r') as f:
settings = json.loads(f.read())

except json.JSONDecodeError:
settings = data
update_fix = True

else:
for info in data:
if info not in settings:
settings[info] = data[info]
update_fix = True

if settings["ScanDelay"] < 30 : settings["ScanDelay"] = 30

Expand Down
16 changes: 9 additions & 7 deletions config/utility/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def data(self) -> List[Dict]:
"""
Lista di dizionari contenente tutta la tabella di conversione.
"""
if not os.path.exists(self.file):
self.write([])
return []


with open(self.file, 'r') as f:
return json.loads(f.read())
if os.path.exists(self.file) and os.path.getsize(self.file) > 0:
try:
with open(self.file, 'r') as f:
return json.loads(f.read())
except json.JSONDecodeError:
pass

self.write([])
return []

@classmethod
def append(self, data: Dict) -> str:
Expand Down

0 comments on commit ce8e2f0

Please sign in to comment.