-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.py
39 lines (33 loc) · 1.12 KB
/
utilities.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
import random
def rand_agent(fname):
lines = open(fname).read().splitlines()
return random.choice(lines)
def human_format(num):
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
return "%.2f%s" % (num, ["", "K", "M", "G", "T", "P"][magnitude])
def str_time(intrv):
intrv = intrv.total_seconds()
hours = intrv // 3600
minutes = (intrv % 3600) // 60
if hours == 1:
if minutes > 1:
return str(int(hours)) + " hour " + str(int(minutes)) + " minutes"
elif minutes == 1:
return str(int(hours)) + " hour " + str(int(minutes)) + " minute"
else:
return str(int(hours)) + " hour "
elif hours == 2:
if minutes > 1:
return str(int(hours)) + " hours " + str(int(minutes)) + " minutes"
elif minutes == 1:
return str(int(hours)) + " hours " + str(int(minutes)) + " minute"
else:
return str(int(hours)) + " hours "
else:
if minutes > 1:
return str(int(minutes)) + " minutes"
else:
return str(int(minutes)) + " minute"