introduce persistent data storage, which for now just caches rom -> server pairs

This commit is contained in:
Fabian Dill
2020-04-24 05:29:02 +02:00
parent 7582767401
commit 5d33b4b164
4 changed files with 37 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ import sys
import typing
import functools
from yaml import load
from yaml import load, dump
try:
from yaml import CLoader as Loader
@@ -212,6 +212,28 @@ def get_location_name_from_address(address):
return Regions.lookup_id_to_name.get(address, f'Unknown location (ID:{address})')
def persistent_store(category, key, value):
path = local_path("_persistent_storage.yaml")
storage: dict = persistent_load()
category = storage.setdefault(category, {})
category[key] = value
with open(path, "wt") as f:
f.write(dump(storage))
def persistent_load():
path = local_path("_persistent_storage.yaml")
storage: dict = {}
if os.path.exists(path):
try:
with open(path, "r") as f:
storage = parse_yaml(f.read())
except Exception as e:
import logging
logging.debug(f"Could not read store: {e}")
return storage
class ReceivedItem(typing.NamedTuple):
item: int
location: int