diff --git a/.gitignore b/.gitignore index 664ada9..8a5bf70 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ [Ss]cripts pyvenv.cfg .venv -pip-selfcheck.json \ No newline at end of file +pip-selfcheck.json +*.json +__pycache__ \ No newline at end of file diff --git a/__pycache__/test.cpython-38.pyc b/__pycache__/test.cpython-38.pyc deleted file mode 100644 index ecb3996..0000000 Binary files a/__pycache__/test.cpython-38.pyc and /dev/null differ diff --git a/test.py b/test.py index 745f464..5e2bb2e 100644 --- a/test.py +++ b/test.py @@ -14,14 +14,17 @@ def preprocess(): print('start init alarms and logs') #versuch beide files zu laden, wenn das fehlschlägt, initiiere beide files als json - try: - logsFile = json.load(open("./logs.json")) - alarmsFile = json.load(open("./alarms.json")) - except:#no worky - print("initiate logs.json") - logsFile=json.load(open("./logs.json","w").write("{}")) - print("initiate alarms.json") - alarmsFile=json.load(open("./alarms.json","w").write("{}")) + with open('alarms.json', 'w') as f, open('logs.json','w') as g: + try: + alarmsFile = json.load(f) + logsFile = json.load(g) + except: + alarmsFile = list() + logsFile = list() + json.dump(alarmsFile, f, indent=2) + json.dump(logsFile, g, indent=2) + f.close() + g.close() # schreib alle alarme im File in previousAlarms, wenn sie älter als 2 mins sind # alle anderen in active alarms for alarm in alarmsFile: