-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
54 lines (45 loc) · 1.28 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import math
import os
def get_field(o: dict, *fields):
current = o
for field in fields:
current = current.get(field)
if current is not None:
continue
else:
return None
return current
SEC_PER_MIN = 60
SEC_PER_HOUR = SEC_PER_MIN * 60
SEC_PER_DAY = SEC_PER_HOUR * 8
SEC_PER_WEEK = SEC_PER_DAY * 5
def format_time(t: int, useHours=False) -> str:
s = ""
rest = t
if not useHours:
weeks = math.floor(rest / SEC_PER_WEEK)
rest -= weeks * SEC_PER_WEEK
if weeks != 0:
s += f" {weeks}w"
days = math.floor(rest / SEC_PER_DAY)
rest -= days * SEC_PER_DAY
if days != 0:
s += f" {days}d"
hours = math.floor(rest / SEC_PER_HOUR)
rest -= hours * SEC_PER_HOUR
if hours != 0:
s += f" {hours}h"
minutes = math.floor(rest / SEC_PER_MIN)
rest -= minutes * SEC_PER_MIN
if minutes != 0:
s += f" {minutes}m"
if rest != 0:
s += f" {rest}s"
return s
def input_bool(__prompt) -> bool:
return input(__prompt).lower() in ['1', 'y', 'yes', 'true']
debug_mode = os.environ.get("DEBUG_MODE") or ""
DEBUG: bool = True if debug_mode.lower() in [1, 'y', 'yes', 'true'] else False
def debug_print(*args):
if DEBUG:
print(args)