dev@locazia: add service wallet
This commit is contained in:
1 parent
164f280899
commit
4a51efed01
13 files changed
+167
-5
No files matched your search
@@ -0,0 +1,32 @@
|
||||
from app.core.logger import make_log
|
||||
from json import loads as json_loads
|
||||
from json import dumps as json_dumps
|
||||
|
||||
|
||||
class ConfigFile:
|
||||
def __init__(self, filepath: str):
|
||||
self.filepath = filepath
|
||||
with open(self.filepath, 'r') as file:
|
||||
self.values = json_loads(file.read())
|
||||
|
||||
assert isinstance(self.values, dict)
|
||||
|
||||
def get(self, key, default=None):
|
||||
return self.values.get(key, default)
|
||||
|
||||
def save(self):
|
||||
with open(self.filepath, 'w') as file:
|
||||
file.write(
|
||||
json_dumps(
|
||||
self.values,
|
||||
indent=4,
|
||||
sort_keys=True
|
||||
)
|
||||
)
|
||||
|
||||
def set(self, key, value):
|
||||
self.values[key] = value
|
||||
self.save()
|
||||
make_log("ConfigFile", f"Edited {key}", level="debug")
|
||||
|
||||
|
||||
Reference in new issue
Block a user