def json_dict(self) -> dict: attempts = 0 json_dict = JsonSerializer.get_dictionary(self.json_file) while len(json_dict) == 0: sleep(0.2) # Prevents parallel access errors to file json_dict = JsonSerializer.get_dictionary(self.json_file) attempts += 1 if attempts >= 5: break return sort_dict(dict(sorted( json_dict.items(), key=lambda e: int(e[1]['number']), reverse=True )))
def __add__(key, element): dictionary = JsonSerializer.get_dictionary(APP_SETTINGS) elements = dictionary.get(key) if type(elements) != list: elements = [] if element not in elements: elements.append(element) dictionary[key] = elements JsonSerializer.set_dictionary(dictionary, APP_SETTINGS) return True
def __remove__(key, element): dictionary = JsonSerializer.get_dictionary(APP_SETTINGS) if dictionary.get(key) is None: return True if element == '*': # Rimuove tutti gli elementi dictionary[key] = [] JsonSerializer.set_dictionary(dictionary, APP_SETTINGS) return True elements = dictionary[key] if element in elements: elements.remove(element) dictionary[key] = elements JsonSerializer.set_dictionary(dictionary, APP_SETTINGS) return True
def __set__(key, value): dictionary = JsonSerializer.get_dictionary(APP_SETTINGS) dictionary[key] = value JsonSerializer.set_dictionary(dictionary, APP_SETTINGS) return True
def __get__(key=None): dictionary = JsonSerializer.get_dictionary(APP_SETTINGS) if key is None: return dictionary return dictionary.get(key)
def __init__(self): self._manufacturer_dict = JsonSerializer.get_dictionary( MacManufacturer._MANUFACTURERS_JSON) self._update_manufacturer_dict()