-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimleaguesAPI.py
More file actions
85 lines (60 loc) · 3.34 KB
/
imleaguesAPI.py
File metadata and controls
85 lines (60 loc) · 3.34 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
import requests
import json
import uuid
class ImLeaguesAPI:
def __init__(self, username, password, schoolId):
self.login(username, password, schoolId)
def registerEvent(self, studentId, eventId):
loginUrl = 'https://www.imleagues.com/Services/AjaxRequestHandler.ashx?class=imLeagues.Web.Members.Services.BO.Fitness.RegisterEventBO&method=RegisterSession¶mType=imLeagues.Internal.API.VO.Input.Fitness.RegisterSessionInVO'
cookies = {'ASP.NET_SessionId': self.sessionId}
data = {"eventId": eventId,
"acceptTerms": True,
"sid": studentId,
"allowSMSMessage":False,
"allowMobileAppSMS":True,
"allowSessionReminder":True,
"remindDays":1}
response = requests.post(loginUrl, data = json.dumps(data), cookies = cookies).json()
if response['isDone'] == False:
raise EventRegistrationError(response)
return f"Event: {eventId} registration was successful!"
def login(self, username, password, schoolId):
sessionIdUrl = 'https://www.imleagues.com/Services/AjaxRequestHandlerWithWritableSession.ashx?class=imLeagues.Web.Members.Services.BO.Account.LoginBO&method=Initialize¶mType=imLeagues.Internal.API.VO.Input.InitLoginInViewVO&urlReferrer=https://www.imleagues.com/spa/account/login'
sessionId = requests.post(sessionIdUrl, data = json.dumps({'entityType':'account'}))
sessionId = sessionId.cookies['ASP.NET_SessionId']
self.sessionId = sessionId
self.schoolId = schoolId
loginUrl = 'https://www.imleagues.com/Services/AjaxRequestHandlerWithWritableSession.ashx?class=imLeagues.Web.Members.Services.BO.Account.LoginBO&method=Login¶mType=imLeagues.Internal.API.VO.Input.LoginInSchoolVO&urlReferrer=https://www.imleagues.com/spa/account/enterpass'
cookies = {'ASP.NET_SessionId': sessionId}
data = {'email': username,
'password': password,
'schoolId': schoolId }
loginRequest = requests.post(loginUrl, data = json.dumps(data), cookies = cookies)
successfulLogin = loginRequest.json()['isDone']
if successfulLogin == False:
raise AuthenticationError("The login was unsuccesful")
return sessionId
def getEventInfo(self, eventId):
url = 'https://www.imleagues.com/Services/AjaxRequestHandler.ashx?class=imLeagues.Web.Members.Services.BO.Fitness.ViewEventBO&method=Initialize¶mType=imLeagues.Internal.API.VO.Input.Fitness.GetViewEventVMInVO'
cookies = {'ASP.NET_SessionId': self.sessionId}
data = {"entityType":"fitness",
"entityId": self.schoolId,
"pageType":"Fitness",
"eventId": eventId}
eventDetails = requests.post(url, data = json.dumps(data), cookies = cookies).json()
if eventDetails['isDone'] == False:
raise EventDoesNotExist("The requested event does not exist")
return eventDetails['data']['sessionOutVM']['session']
class AuthenticationError(Exception):
"""Raised when the authentication is unsuccessful"""
pass
class EventDoesNotExist(Exception):
"""Raised when an event does not exist"""
pass
class EventHasAlreadyOccurred(Exception):
"""Raised when an event has already occcured"""
pass
class EventAlreadyAdded(Exception):
"""Raised when an event is already in the config file"""
class EventRegistrationError(Exception):
"""Raised when there is an error with event registration"""