improve set_getters a bit

This commit is contained in:
Fabian Dill 2021-02-25 04:14:46 +01:00
parent f19291aaed
commit e5e70db380
2 changed files with 9 additions and 5 deletions

View File

@ -105,12 +105,18 @@ class Context():
self.set_getters(network_data_package)
def set_getters(self, data_package: dict, network=False):
if not network:
if not network: # local data; check if newer data was already downloaded
local_package = Utils.persistent_load().get("datapackage", {}).get("latest", {})
if local_package and local_package["version"] > network_data_package["version"]:
data_package: dict = local_package
elif network and data_package["version"] > network_data_package["version"]:
Utils.persistent_store("datapackage", "latest", network_data_package)
elif network: # check if data from server is newer
for key, value in data_package.items():
if type(value) == dict: # convert to int keys
data_package[key] = \
{int(subkey) if subkey.isdigit() else subkey: subvalue for subkey, subvalue in value.items()}
if data_package["version"] > network_data_package["version"]:
Utils.persistent_store("datapackage", "latest", network_data_package)
item_lookup: dict = data_package["lookup_any_item_id_to_name"]
locations_lookup: dict = data_package["lookup_any_location_id_to_name"]

View File

@ -13,5 +13,3 @@ lookup_any_location_id_to_name = {**Regions.lookup_id_to_name, **Locations.looku
network_data_package = {"lookup_any_location_id_to_name": lookup_any_location_id_to_name,
"lookup_any_item_id_to_name": lookup_any_item_id_to_name,
"version": 1}
print(network_data_package)