Do not crash with malformed visitors.json files
If the visitors.json file does not contain a valid JSON file, reset it, and act as if it was empty.pull/35/head
parent
f243391418
commit
acea6018a6
|
@ -229,6 +229,7 @@ class Plant(object):
|
|||
visitors_this_check = []
|
||||
if os.path.isfile(visitor_filepath):
|
||||
with open(visitor_filepath, 'r') as visitor_file:
|
||||
try:
|
||||
data = json.load(visitor_file)
|
||||
if data:
|
||||
for element in data:
|
||||
|
@ -245,6 +246,9 @@ class Plant(object):
|
|||
pass
|
||||
with open(visitor_filepath, 'w') as visitor_file:
|
||||
visitor_file.write('[]')
|
||||
except:
|
||||
with open(visitor_filepath, 'w') as visitor_file:
|
||||
visitor_file.write('[]')
|
||||
else:
|
||||
with open(visitor_filepath, mode='w') as f:
|
||||
json.dump([], f)
|
||||
|
|
Loading…
Reference in New Issue