-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurlForACurl.py
More file actions
executable file
·138 lines (104 loc) · 4.43 KB
/
curlForACurl.py
File metadata and controls
executable file
·138 lines (104 loc) · 4.43 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
#!/usr/bin/env python3
from imleaguesAPI import *
from datetime import datetime as dt, timedelta
from jsonManager import JsonManager
class CurlForACurl:
def __init__(self):
self.configManager = JsonManager()
self.config = self.configManager.readConfig()
print("\n Welcome to the CurlForACurl Auto Registration System!\n")
print("Please enter your email address: ", end="")
email = input()
if not email:
email = self.config['defaults']['email']
newUser = True
for i in range(len(self.config['users'])):
if self.config['users'][i]['email'] == email:
currentUser = i
newUser = False
if newUser == True :
self.setUpUser(email)
currentUser = len(self.config['users']) - 1
else:
self.imLeaguesAPI = ImLeaguesAPI(email, self.config['users'][currentUser]['password'], self.config['users'][currentUser]['schoolId'])
print('\nWelcome Back ' + email + "!")
self.addEvent(currentUser)
def addEvent(self, currentUser):
alreadyAddedEventIds = []
for event in self.config['users'][currentUser]['eventIds']:
alreadyAddedEventIds.append(event['eventId'])
addEventId = True
while addEventId == True:
print("Please enter a WellRec/imLeagues event ID or link: ", end="")
eventId = input()
if "eventId=" in eventId:
eventId = eventId.split("eventId=",1)[1]
try:
for alreadyAddedId in alreadyAddedEventIds:
if eventId == alreadyAddedId:
raise EventAlreadyAdded
eventInfo = self.imLeaguesAPI.getEventInfo(eventId)
startDate = eventInfo['startDateDescription']
startDate = dt.strptime(startDate, '%A, %B %d, %Y').date()
if startDate <= dt.today().date():
raise EventHasAlreadyOccurred
elif startDate <= (dt.today().date() + timedelta(days=1)):
try:
print(self.imLeaguesAPI.registerEvent(self.config['users'][currentUser]['studentId'], eventId))
except EventRegistrationError as e:
print(f"Error: Event Id: {eventId} Message: {e}")
else:
# Registration opens the day before
startDate = startDate - timedelta(days = 1)
startDate = startDate.isoformat()
data = {'registrationDay': startDate, 'eventId': eventId}
self.config['users'][currentUser]['eventIds'].append(data)
self.configManager.writeConfig(self.config)
alreadyAddedEventIds.append(eventId)
print(f"{eventInfo['subject']} is successful queued for preregistration on {startDate}!")
except EventDoesNotExist:
print("Error: The selected event does not exist. Please choose a different event.")
except EventHasAlreadyOccurred:
print("Error: The selected event has already occured or takes place today. Please choose a different event.")
except EventAlreadyAdded:
print("Error: The selected event has already been added for this user. Please choose a different event.")
invalidResponse = True
while invalidResponse:
print("Would you like to preregister another event? (y/n): ", end="")
response = str(input())[0].lower()
if response == 'y':
invalidResponse = False
elif response == 'n':
addEventId = False
invalidResponse = False
else:
print('Please enter yes or no (y/n)')
def setUpUser(self, email):
successfulLogin = False
while successfulLogin == False:
print("Please enter your IMLeagues password: ", end="")
password = input()
print("Enter your student ID (Can be left blank if preferred): ", end="")
studentId = input()
print("Enter your school ID code (Leave blank if unknown): ", end="")
schoolId = input()
if not studentId:
studentId = self.config['defaults']['studentId']
if not schoolId:
schoolId = self.config['defaults']['schoolId']
print(f"Creating user {email}...\n")
data = {'email': email,
'password': password,
'schoolId': schoolId,
'studentId': studentId,
'eventIds': []
}
try:
self.imLeaguesAPI = ImLeaguesAPI(email, password, schoolId)
successfulLogin = True
except AuthenticationError:
print("Incorrect email/password")
continue
self.config['users'].append(data)
self.configManager.writeConfig(self.config)
CurlForACurl()