mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
24 lines
543 B
Python
24 lines
543 B
Python
|
import json
|
||
|
import os
|
||
|
|
||
|
filename = "config.json"
|
||
|
|
||
|
|
||
|
class Config:
|
||
|
|
||
|
def __init__(self):
|
||
|
self.config_dict = json.loads(open(filename).read()) if os.path.exists(filename) else dict()
|
||
|
|
||
|
def get(self, key, default=None):
|
||
|
if key in self.config_dict:
|
||
|
return self.config_dict[key]
|
||
|
return default
|
||
|
|
||
|
def set(self, key, value):
|
||
|
self.config_dict[key] = value
|
||
|
self.save_config()
|
||
|
|
||
|
def save_config(self):
|
||
|
with open(filename, 'w') as f:
|
||
|
f.write(json.dumps(self.config_dict))
|