-
Notifications
You must be signed in to change notification settings - Fork 0
/
book_users.py
executable file
·40 lines (35 loc) · 1.13 KB
/
book_users.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
# Jaime Bohorquez
# Programmed using Atom + iTerm2 on Mac OS Big Sur
# Filename: create_booking
# Whenever this script runs, we get our users from the UserInfo.JSON and send
# post requests for a booking.
from gym_requests import GymRequest
from user import GymUser as User
import json
# For obvious reasons this file was .gitignored.
# See example file to create your own.
file_info = open('./json/UserInfo.JSON', encoding='utf-8')
data = json.load(file_info)
users = []
json_users = data["users"]
for json_user in json_users:
users.append(User(
name=json_user["name"],
email=json_user["email"],
time=json_user["time"],
room=json_user["room"]
)
)
attempts = 0
limit_of_attempts = 30
for user in users:
req = GymRequest(user)
while attempts < limit_of_attempts:
resp = req.post_request()
if "Booking" in resp.json():
print("Booked for", user.name, "at", user.time + ".")
break
print("Retrying...")
attempts += 1
if attempts == limit_of_attempts:
print("Failed to book for", user.name, "at", user.time + ".")