feat: cleaned up

This commit is contained in:
2024-04-09 12:55:35 +02:00
parent fe81fee82b
commit 2e5a46c3f6
5 changed files with 36 additions and 28 deletions

View File

@@ -1,13 +1,19 @@
from datetime import datetime
from pathlib import Path
import json
import logging
from .shared import DEBUG, DEBUG_LOGGING, DEBUG_PAGES
from .config import config, read_config, write_config
from .enums.colors import BColors
from .path_manager import LOCATIONS
DEBUG = False
"""
Here are all global important functions.
IO functions
"""
def _apply_color(msg: str, color: BColors) -> str:
if color is BColors.ENDC:
return msg
@@ -22,6 +28,31 @@ def user_input(msg: str, color: BColors = BColors.ENDC):
return input(_apply_color(msg, color)).strip()
def dump_to_file(file_name: str, payload: str, is_json: bool = False, exit_after_dump: bool = False):
if not DEBUG_PAGES:
return
path = Path(LOCATIONS.TEMP_DIRECTORY, file_name)
logging.warning(f"dumping {file_name} to: \"{path}\"")
if is_json:
payload = json.dumps(json.loads(payload), indent=4)
if isinstance(payload, dict):
payload = json.dumps(payload, indent=4)
with path.open("w") as f:
f.write(payload)
if exit_after_dump:
exit()
"""
misc functions
"""
def get_current_millis() -> int:
dt = datetime.now()
return int(dt.microsecond / 1_000)

View File

@@ -1,21 +0,0 @@
from pathlib import Path
import json
from .path_manager import LOCATIONS
def dump_to_file(file_name: str, payload: str, is_json: bool = False, exit_after_dump: bool = True):
path = Path(LOCATIONS.TEMP_DIRECTORY, file_name)
print(f"Dumping payload to: \"{path}\"")
if is_json:
payload = json.dumps(json.loads(payload), indent=4)
if isinstance(payload, dict):
payload = json.dumps(payload, indent=4)
with path.open("w") as f:
f.write(payload)
if exit_after_dump:
exit()