-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
116 lines (89 loc) · 2.82 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
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
###########################################################
############ Created by ORASHAR on 08/05/2020 ############
###########################################################
import sys
from datetime import date
import time
import emailService
import validator
import request_handler
import random
import notify
import sys
## system info
SYSTEM = sys.platform
# setting up params
PINCODE = -1#input("enter pincode: ")
DATE = date.today()
DATE = DATE.strftime("%d-%m-%Y")
AGE_LIMIT = -1
EMAIL = ""
DELAY = random.randint(60,120)
def inputs():
invalid_count = 0
pincode = input("Enter Pincode: ")
while not validator.validate_pincode(pincode):
invalid_count += 1
print("invalid pincode")
pincode = input("Enter Pincode: ")
if(invalid_count > 10): sys.exit("Too many invalid inputs")
global PINCODE
PINCODE = pincode
age_limit = int(input("Age limit ( 18 / 45 )"))
while not validator.validate_agelimit:
invalid_count += 1
print("invalid Age limit")
age_limit = int(input("Age limit ( 18 / 45 )"))
if(invalid_count > 10): sys.exit("Too many invalid inputs")
global AGE_LIMIT
AGE_LIMIT = age_limit
email = input("Email to get notified: ")
while not validator.validate_email(email):
invalid_count += 1
print("invalid Email")
email = input("Email to get notified: ")
if(invalid_count > 10): sys.exit("Too many invalid inputs")
global EMAIL
EMAIL = email
def main():
if PINCODE == -1:
inputs()
# constraints
constraints = {
"AGE_LIMIT": AGE_LIMIT,
}
available_centers = {}
res_json = request_handler.fetchData(PINCODE, DATE)
if not res_json:
print("Could not perform the search.")
else:
available_centers = request_handler.parseData(res_json, constraints)
# If no centers available
if len(available_centers) == 0:
print(f"No centers available for selected Age group")
else:
if SYSTEM == "linux" or platform == "linux2": notify.showNotification(PINCODE)
emailService.sendEmail(available_centers, EMAIL, PINCODE)
print("Attempt done")
def timer(sec):
for remaining in range(sec, 0, -1):
sys.stdout.write("\r")
sys.stdout.write(f"Next attempt after {remaining} seconds")
sys.stdout.flush()
time.sleep(1)
if __name__ == "__main__":
print("This program check vaccine availability every 60 seconds and notifies you via email")
attempt = 0
starttime=time.time()
while True:
attempt += 1
sys.stdout.write(f"Attempt no: {attempt}\n")
sys.stdout.flush()
try:
main()
DELAY = random.randint(60,120)
timer(DELAY)
except Exception as e:
if SYSTEM == "linux" or platform == "linux2": notify.showError()
print(e)
break;