Initial Commit

This commit is contained in:
Firq 2024-06-29 14:14:18 +02:00
commit bcafbeb3cf
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
12 changed files with 140 additions and 0 deletions

View file

View file

View file

@ -0,0 +1,26 @@
import pathlib
import base64
import yaml
_storagepath = pathlib.Path(__file__).parents[1] / ".temp"
_file = _storagepath / "storage.yaml"
_storagepath.mkdir(exist_ok=True, parents=True)
def set(key: str, value: str):
with open(_file, "w+") as file:
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
content.update({ key: base64.b64encode(value.encode()) })
yaml.dump(content, file, Dumper=yaml.SafeDumper)
def get(key: str):
value: str = None
if not _file.exists():
return None
with open(_file, "r") as file:
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader)
value = content.get(key, None)
return base64.b64decode(value).decode() if value is not None else None
def clear():
_file.unlink()