Initial commit
This commit is contained in:
22
modules/colors.py
Normal file
22
modules/colors.py
Normal file
@@ -0,0 +1,22 @@
|
||||
RESET = '\u001b[0m'
|
||||
|
||||
BLACK = '\u001b[30m'
|
||||
RED = '\u001b[31m'
|
||||
GREEN = '\u001b[32m'
|
||||
YELLOW = '\u001b[33m'
|
||||
BLUE = '\u001b[34m'
|
||||
MAGENTA = '\u001b[35m'
|
||||
CYAN = '\u001b[36m'
|
||||
WHITE = '\u001b[37m'
|
||||
|
||||
BBLACK = '\u001b[30;1m'
|
||||
BRED = '\u001b[31;1m'
|
||||
BGREEN = '\u001b[32;1m'
|
||||
BYELLOW = '\u001b[33;1m'
|
||||
BBLUE = '\u001b[34;1m'
|
||||
BMAGENTA = '\u001b[35;1m'
|
||||
BCYAN = '\u001b[36;1m'
|
||||
BWHITE = '\u001b[37;1m'
|
||||
|
||||
ULINE = '\u001b[4m'
|
||||
REVERSE = '\u001b[7m'
|
4
modules/logging.py
Normal file
4
modules/logging.py
Normal file
@@ -0,0 +1,4 @@
|
||||
def logWrite(message):
|
||||
# save to log file and rotation is to be done
|
||||
# logAppend(f"[{nowtime()}] {message}", flush=True)
|
||||
print(f"{message}", flush=True)
|
54
modules/utils.py
Normal file
54
modules/utils.py
Normal file
@@ -0,0 +1,54 @@
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
|
||||
|
||||
def jsonLoad(filename):
|
||||
"""Loads arg1 as json and returns its contents"""
|
||||
with open(filename, "r", encoding='utf8') as file:
|
||||
output = json.loads(file.read())
|
||||
file.close()
|
||||
return output
|
||||
|
||||
def jsonSave(contents, filename):
|
||||
"""Dumps dict/list arg1 to file arg2"""
|
||||
with open(filename, "w", encoding='utf8') as file:
|
||||
file.write(json.dumps(contents, ensure_ascii=False, indent=4))
|
||||
file.close()
|
||||
return
|
||||
|
||||
|
||||
def configSet(key: str, value, *args: str):
|
||||
"""Set key to a value
|
||||
Args:
|
||||
* key (str): The last key of the keys path.
|
||||
* value (str/int/float/list/dict/None): Some needed value.
|
||||
* *args (str): Path to key like: dict[args][key].
|
||||
"""
|
||||
this_dict = jsonLoad("config.json")
|
||||
string = "this_dict"
|
||||
for arg in args:
|
||||
string += f'["{arg}"]'
|
||||
if type(value) in [str]:
|
||||
string += f'["{key}"] = "{value}"'
|
||||
else:
|
||||
string += f'["{key}"] = {value}'
|
||||
exec(string)
|
||||
jsonSave(this_dict, "config.json")
|
||||
return
|
||||
|
||||
def configGet(key: str, *args: str):
|
||||
"""Get value of the config key
|
||||
Args:
|
||||
* key (str): The last key of the keys path.
|
||||
* *args (str): Path to key like: dict[args][key].
|
||||
Returns:
|
||||
* any: Value of provided key
|
||||
"""
|
||||
this_dict = jsonLoad("config.json")
|
||||
this_key = this_dict
|
||||
for dict_key in args:
|
||||
this_key = this_key[dict_key]
|
||||
return this_key[key]
|
Reference in New Issue
Block a user