This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utility.py
69 lines (53 loc) · 1.89 KB
/
Utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from datetime import datetime
from distutils.util import strtobool
import os
class TerminalColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class Utility:
@staticmethod
def timestamp_log_message(log_message):
return f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')}::{log_message}"
@staticmethod
def log_verbose(log_message):
print(f"{TerminalColors.OKBLUE}{Utility.timestamp_log_message(log_message)}{TerminalColors.ENDC}")
@staticmethod
def log_information(log_message):
print(f"{TerminalColors.OKGREEN}{Utility.timestamp_log_message(log_message)}{TerminalColors.ENDC}")
@staticmethod
def log_warning(log_message):
print(f"{TerminalColors.WARNING}{Utility.timestamp_log_message(log_message)}{TerminalColors.ENDC}")
@staticmethod
def log_error(log_message):
print(f"{TerminalColors.FAIL}{Utility.timestamp_log_message(log_message)}{TerminalColors.ENDC}")
@staticmethod
def parse_price_string(price_string):
cleaned_price_string = price_string \
.replace(",", "") \
.replace("$", "") \
.replace("£", "") \
.replace("€", "")
parsed_price = float(cleaned_price_string)
return parsed_price
@staticmethod
def beep():
print("\a")
@staticmethod
def get_config_value_str(config_key):
return os.environ.get(config_key)
@staticmethod
def get_config_value_int(config_key):
return int(os.environ.get(config_key))
@staticmethod
def get_config_value_float(config_key):
return float(os.environ.get(config_key))
@staticmethod
def get_config_value_bool(config_key):
return bool(strtobool(os.environ.get(config_key)))