-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.py
95 lines (78 loc) · 2.24 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Time
from datetime import datetime
from datetime import timedelta
from pytz import timezone
"""""""""
General
"""""""""
# Check if input is filled or no
def is_filled(data):
if data is None:
return False
if data == '':
return False
if data == []:
return False
if data == {}:
return False
if data == ():
return False
return True
"""
Time
"""
# My Default Timezone
def default_timezone():
_tz = timezone('Europe/Rome')
return(_tz)
# Now Time with Formatter or not
def my_time_now(_what_format = False):
_my_timezone = default_timezone()
if not _what_format:
_now = datetime.now(_my_timezone)
else:
_now = datetime.now(_my_timezone).strftime("%Y-%m-%d %H:%M:%S")
return(_now)
# TimeStamp milliseconds Formatter
def timestamp_formatter(_date):
_my_timezone = default_timezone()
_my_date = datetime.fromtimestamp(_date/1000, _my_timezone).strftime('%Y-%m-%d %H:%M:%S')
return(_my_date)
"""""""""
STRING
"""""""""
def split_string_into_list(txt, separator):
# Prepare
_list = []
_slices = None
_slices = txt.split(separator)
for _slice in _slices:
if bool(_slice):
if _slice == 'None':
_slice = None
_list.append(_slice)
return(_list)
"""
Log
"""
def my_log(_type, _module, _func_name, _func_line, _inputs ,_msg,_clean=True):
# Prepare
_msg_error_complete = None
_msg_return = None
_response_split = None
_where = f"{_module}.{_func_name}"
# Build Error Msg
if _inputs is not None:
_msg_error_complete = f"{_type} on {_where}, line {_func_line} with inputs {_inputs} -- MESSAGE: {my_time_now(True)} - {_type.upper()} - {_msg}"
else:
_msg_error_complete = f"{_type} on {_where}, line {_func_line} -- MESSAGE: {my_time_now(True)} - {_type.upper()} - {_msg}"
# Return Nice Msg for Users or Not
if _clean:
_response_split = split_string_into_list(_msg_error_complete,'MESSAGE: ')
if _response_split:
_msg_return = _response_split[-1]
else:
_msg_return = _msg_error_complete
else:
_msg_return = _msg_error_complete
return(_msg_return)