-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
52 lines (45 loc) · 1.61 KB
/
main.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
import datetime
import os
import time
import checker
import mailer
LAST_EMAIL = datetime.datetime.now()
data = []
def init_request():
timestamp = datetime.datetime.now()
error, result = checker.check()
status = ''
if error:
status = 'error'
elif result:
status = 'active'
else:
status = 'inactive'
data.append({'status': status, 'timestamp': timestamp})
def take_action():
global EMAIL_AFTER
global LAST_EMAIL
global data
status = data[-1]['status']
if status != 'inactive':
if status == 'active':
mailer.send_mail('URGENT: Appointment Open!', 'New Appointment: https://service2.diplo.de/rktermin/extern/choose_realmList.do?locationCode=isla&request_locale=en \n Cancel Old Appointment: https://mail.google.com/mail/u/0/#search/diplo.de/FMfcgzGqRZXPdJGVVpMQhfsGWkVbcWxC')
elif status == 'error':
mailer.send_mail('ERROR: Something went wrong!', 'Something went wrong on the server. Kindly check!')
elif datetime.datetime.now() > LAST_EMAIL + datetime.timedelta(minutes=int(os.environ.get('EMAIL_AFTER_MIN'))):
content_list = []
for d in data:
content_list.append(str(d['timestamp']) + ' -> ' + d['status'])
mailer.send_mail('Summary', '\n'.join(content_list))
data = []
LAST_EMAIL = datetime.datetime.now()
def main():
i = 1
while True:
print('Cycle ' + str(i) + ':', datetime.datetime.now())
init_request()
take_action()
time.sleep(int(os.environ.get('CHECK_AFTER_SEC')))
i += 1
if __name__ == '__main__':
main()