You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
746 B
37 lines
746 B
1 week ago
|
import json
|
||
|
import os
|
||
|
|
||
|
from .logging import logger
|
||
|
from .constants import Constants
|
||
|
|
||
|
|
||
|
def load_storage():
|
||
|
if os.path.exists(Constants.STORAGE):
|
||
|
logger.debug(f"Loading storage from {Constants.STORAGE}")
|
||
|
with open(Constants.STORAGE, "r") as f:
|
||
|
return json.load(f)
|
||
|
return {}
|
||
|
|
||
|
|
||
|
def save_storage(data):
|
||
|
with open(Constants.STORAGE, "w") as f:
|
||
|
json.dump(data, f)
|
||
|
|
||
|
|
||
|
def save_to_storage(key, value):
|
||
|
storage = load_storage()
|
||
|
storage[key] = value
|
||
|
save_storage(storage)
|
||
|
|
||
|
|
||
|
def load_from_storage(key):
|
||
|
storage = load_storage()
|
||
|
if key in storage:
|
||
|
return storage[key]
|
||
|
return {}
|
||
|
|
||
|
|
||
|
def clear_storage():
|
||
|
if os.path.exists(Constants.STORAGE):
|
||
|
os.remove(Constants.STORAGE)
|