-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.py
81 lines (65 loc) · 1.56 KB
/
Utils.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
import sys
def seconds2timeStr(secs):
seconds = secs % 60
minutes = (secs / 60) % 60
hours = (secs / (60*60)) % 24
days = (secs / (60*60*24))
time = []
if days > 1:
time.append(str(days) + " days")
elif days == 1:
time.append("1 day")
if hours > 1:
time.append(str(hours) + " hours")
elif hours == 1:
time.append("1 hour")
if minutes > 1:
time.append(str(minutes) + " minutes")
elif minutes == 1:
time.append("1 minute")
if seconds > 1:
time.append(str(seconds) + " seconds")
elif seconds == 1:
time.append("1 second")
if time != []:
last = time.pop()
if time != []:
return ', '.join(time) + " and " + last
else:
return last
def date2string(d):
day = date2str(d.day)
month = date2str(d.month)
year = date2str(d.year)
hour = date2str(d.hour)
minute = date2str(d.minute)
second = date2str(d.second)
return (str(hour) + ":" + str(minute) + ":" + str(second) + " " + str(day) + "/" + str(month))
def date2str(objDate):
s = str(objDate)
if len(s) == 1:
s = "0" + s
return s
def tags2list(tags):
tagsList = []
for tag in tags:
tagsList.append(tag['Name'])
return tagsList
def blogs2list(other_accounts):
oaList = []
for oa in other_accounts:
oaList.append(oa['Name'])
return oaList
def binarySearch(elem, lst):
if lst == []:
return False
index_pivot = int(len(lst)/float(2))
if lst[index_pivot] == elem:
return True
elif lst[index_pivot] > elem:
return binarySearch(elem, lst[:index_pivot])
else:
return binarySearch(elem, lst[(index_pivot+1):])
def write(s):
sys.stdout.write(s)
sys.stdout.flush()