-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
38 lines (31 loc) · 1.01 KB
/
util.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
import datetime
import math
def log(text, sameline=True):
now = datetime.datetime.now()
if sameline: linecontrol = '\r'
else: linecontrol = '\n'
print(now.strftime("%Y%m%d %H:%M:%S") + '> ' + text, end=linecontrol)
intervals = (
('weeks', 604800), # 60 * 60 * 24 * 7
('days', 86400), # 60 * 60 * 24
('hours', 3600), # 60 * 60
('minutes', 60),
('seconds', 1),
)
def display_friendly_time(seconds, granularity=2):
result = []
for name, count in intervals:
value = seconds // count
if value:
seconds -= value * count
if value == 1:
name = name.rstrip('s')
result.append("{} {}".format(math.floor(value), name))
return ', '.join(result[:granularity])
def get_current_time_of_the_day():
now = datetime.datetime.now()
return int(now.strftime("%H"))
def get_current_day():
return int(datetime.datetime.now().strftime("%d"))
def get_current_week_day():
return datetime.datetime.now().weekday()