-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods.py
More file actions
198 lines (171 loc) · 4.77 KB
/
Copy pathMethods.py
File metadata and controls
198 lines (171 loc) · 4.77 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import Events
import datetime
def select_suffix(day):
st = [1, 21, 31]
nd = [2, 22]
rd = [3, 23]
if day in st:
return "st"
elif day in nd:
return "nd"
elif day in rd:
return "rd"
else:
return "th"
def add_item(array, reminder: Events.Reminder = None, event: Events.Event = None): # Adds an item to a dynamic array
# Detect which case we are working with, this function is convenient because it provides the ability to add other
# types of events and their lists
if reminder is None and event is None:
return False
elif reminder is None:
item = event
elif event is None:
item = reminder
else:
return False
# Algorithm to add item to the first blank element or append it to the end
blank_found = False
for i in range(len(array)):
if array[i] == 0:
item.index = i
array[i] = item.index
blank_found = True
break
if not blank_found:
item.index = len(array) - 1
array.append(item)
def remove_item(array, reminder: Events.Reminder = None, event: Events.Event = None): # Removes an item from a dynamic array
if reminder is None and event is None:
return False
elif reminder is None:
item = event
elif event is None:
item = reminder
else:
return False
if item.index == len(array) - 1:
array.pop(item.index)
else:
array[item.index] = 0
def string_to_duration(st): # Method to convert string of format 20:30:30 or 30:30 or 30s or 1h2m30s into a duration
st = st.lower()
time_split = st.find(':')
timer = 0
if time_split == -1:
h_i = st.find("h")
m_i = st.find("m")
s_i = st.find("s")
if h_i != -1:
hour = st[0:h_i]
if m_i != -1:
minute = st[h_i + 1:m_i]
if s_i != -1:
second = st[m_i + 1:s_i]
else:
second = 0
else:
minute = 0
if s_i != -1:
second = st[h_i + 1:s_i]
else:
second = 0
elif m_i != -1:
hour = 0
minute = st[0:m_i]
if s_i != -1:
second = st[m_i + 1:s_i]
else:
second = 0
else:
hour = 0
minute = 0
if s_i != -1:
second = st[0:s_i]
else:
second = 0
try:
hour = int(hour)
minute = int(minute)
second = int(second)
except ValueError:
timer = -1
else:
quantity = st.count(":")
if quantity == 1:
second = 0
hour = st[0:time_split]
minute = st[time_split + 1:]
elif quantity == 2:
time_split_2 = st.find(":", time_split + 1)
hour = st[0:time_split]
minute = st[time_split + 1:time_split_2]
second = st[time_split_2 + 1:]
else:
hour = 0
minute = 0
second = 0
try:
hour = int(hour)
minute = int(minute)
second = int(second)
except ValueError:
timer = -1
if timer == -1:
pass
else:
timer = (hour * 3600) + (minute * 60) + second
if timer == 0:
timer = -1
return timer
def string_to_time(st1, st2):
try:
time_split = st1.find(':')
except IndexError:
time_split = -1
if time_split is -1:
try:
# Always use try for this kind of bs so if it fails our bot doesn't crash
hour = int(st1)
try:
minute = int(st2)
except ValueError:
minute = 0
clock = datetime.time(hour, minute, 00)
except ValueError:
hour = -1
minute = -1
clock = -1
else:
try:
hour = int(st1[0:time_split])
try:
minute = int(st1[time_split+1:])
except IndexError:
minute = 0
try:
clock = datetime.time(hour, minute, 00)
except ValueError:
clock = -1
except ValueError:
hour = -1
minute = -1
clock = -1
return clock
def remind_args_to_text(args):
read_key_text = False
text = ""
for arg in args:
if "@" in arg:
read_key_text = False
if read_key_text:
text = text + arg + " "
if arg == "TO":
read_key_text = True
if text != "":
return text
else:
return False
# while True:
# k = input("\n")
# k = k.split()
#