-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutility.py
37 lines (33 loc) · 1.04 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
# Time
from datetime import datetime
from datetime import timedelta
from pytz import timezone
"""
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)
"""
Log
"""
def my_log(_type, _func, _inputs ,_msg):
if _inputs is not None:
_msg_error = f"{my_time_now(True)} {_type} on function {_func} with inputs {_inputs} {chr(10)}MESSAGE: {_msg} {chr(10)}"
else:
_msg_error = f"{my_time_now(True)} {_type} on function {_func} {chr(10)}MESSAGE: {_msg} {chr(10)}"
return(_msg_error)