An error occurred while loading the file. Please try again.
-
Gezer authored
gemacht. timestamp muss noch angepasst werden
a168b48f
import json
import os
def load_json(file_name: str) -> dict:
"""
ladet eine JSON Datei, wenn diese existiert,
und gibt diese als dictionary zurück
key : value
"""
if not os.path.exists(file_name):
return {}
with open(file_name) as f:
mac_room_mapping = json.load(f)
return mac_room_mapping
def write_json(mac_room_mapping: dict, file_name: str):
"""
Nimmt ein dictionary und schreibt dessen
Inhalte in eine JSON Datei
"""
with open(file_name, "w") as f:
f.seek(0)
json.dump(mac_room_mapping, f, indent=4)
f.truncate() # TODO Check if truncate is necessary?