import json import os class DeviceAuth: __filename__ = 'device-auth.json' def __init__(self): print('DeviceAuth init') def device_auth_file_exists(self): return os.path.isfile(self.__filename__) def get_device_auth_details(self): if os.path.isfile(self.__filename__): with open(self.__filename__, 'r') as fp: return json.load(fp) return {} def store_device_auth_details(self, email, details): existing = self.get_device_auth_details() existing[email] = details with open(self.__filename__, 'w') as fp: json.dump(existing, fp)