-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
60 lines (52 loc) · 1.7 KB
/
tools.py
File metadata and controls
60 lines (52 loc) · 1.7 KB
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
from calendar import month_name
class Tools:
def __init__(self):
self.output = ""
def formatDate(self, date):
elements = date.split("-")
return f"{elements[2]}. {month_name[int(elements[1])]} {elements[0]}"
def shortenText(self, string, n): #return first n sentences from string
first = string.find(".")
for _ in range(n - 1):
if not string.find(".", first + 1) == -1:
first = string.find(".", first + 1)
return f"{string[:first-len(string)]}."
def tupleUnpack(self, tup):
self.output = ""
for item in tup:
self.output += f"{item} "
return self.output[:-1]
def joinList(self, list):
self.output = ""
for item in list:
self.output += f"{item}, "
return self.output[:-2] #remove last ', '
def partialJoin(self, list, n):
self.output = ""
i = 0
for item in list:
self.output += f"{item}, "
i += 1
if i >= n:
break
return self.output[:-2]
def processFilmography(self, list, n):
self.output = ""
i = 0
for item in list:
if 'year' in item:
self.output += f"{item['title']} ({item['year']}), "
else:
self.output += f"{item['title'].replace(' ()', '')}, "
i += 1
if i >= n:
break
return self.output[:-2]
def convertTime(self, runtime):
time = int(runtime)
mins = time % 60
hours = int(time / 60)
if hours >= 1:
return f"{hours} h {mins} min"
else:
return f"{mins} min"