feat: Add a tolerance window of 5 minutes for reservation

This commit is contained in:
kbe
2025-07-21 15:19:38 +02:00
parent 18cf2a0a18
commit 3a378c03a6
2 changed files with 224 additions and 29 deletions

View File

@@ -513,39 +513,46 @@ class CrossFitBooker:
logging.error(f"Failed to book {session_type} session at {session_time} - Session: {session}")
def run(self) -> None:
"""
Main execution loop.
"""
# Set up timezone
tz: pytz.timezone = pytz.timezone(TIMEZONE)
"""
Main execution loop.
"""
# Set up timezone
tz: pytz.timezone = pytz.timezone(TIMEZONE)
# Initial login
if not self.login():
logging.error("Authentication failed - exiting program")
return
# Initial login
if not self.login():
logging.error("Authentication failed - exiting program")
return
try:
while True:
try:
current_time: datetime = datetime.now(tz)
logging.info(f"Current time: {current_time}")
try:
while True:
try:
current_time: datetime = datetime.now(tz)
logging.info(f"Current time: {current_time}")
# Always run booking cycle to check for preferred sessions and notify
self.run_booking_cycle(current_time)
# Always run booking cycle to check for preferred sessions and notify
self.run_booking_cycle(current_time)
# Run booking cycle at the target time for actual booking
target_time_str = current_time.strftime("%H:%M")
target_time = datetime.strptime(target_time_str, "%H:%M").replace(year=current_time.year, month=current_time.month, day=current_time.day, tzinfo=tz)
tolerance_window = timedelta(minutes=5)
# Check if current time is within the tolerance window after the target time
if (target_time <= current_time <= (target_time + tolerance_window)):
# Calculate the next booking window
next_booking_window = current_time + timedelta(minutes=20)
# Wait until the next booking window
time.sleep((next_booking_window - current_time).total_seconds())
else:
# Check again in 5 minutes
time.sleep(300)
except Exception as e:
logging.error(f"Unexpected error in booking cycle: {str(e)} - Traceback: {traceback.format_exc()}")
time.sleep(60) # Wait before retrying after error
except KeyboardInterrupt:
self.quit()
# Run booking cycle at the target time for actual booking
if current_time.strftime("%H:%M") == TARGET_RESERVATION_TIME:
# Wait until the next booking window
wait_until = current_time + timedelta(minutes=60)
time.sleep((wait_until - current_time).total_seconds())
else:
# Check again in 5 minutes
time.sleep(300)
except Exception as e:
logging.error(f"Unexpected error in booking cycle: {str(e)} - Traceback: {traceback.format_exc()}")
time.sleep(60) # Wait before retrying after error
except KeyboardInterrupt:
self.quit()
def quit(self) -> None:
"""

188
docs/crossfit_old.txt Normal file
View File

@@ -0,0 +1,188 @@
https://sport.nubapp.com/web/index.php?id_application=81560887#/bookings
curl 'https://sport.nubapp.com/web/ajax/users/checkUser.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://sport.nubapp.com/web/index.php' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Origin: https://sport.nubapp.com' \
-H 'Sec-GPC: 1' \
-H 'Connection: keep-alive' \
-H 'Cookie: applicationId=81560887; AWSALBTG=qZgepZq2iNqzI/cWNnAKBHv6qQNvEDQYbzdJs6cIbqhKfbfFM8GypnXrqH92HmKGpd7kbXgq8wyHjriS2RameqUTePW7wj70Ulvb0yrQC8hE2qq9sX/SDV0Jcv09jIUYiOmoe1P7YoqKve9EtJAJ0oIGXsvuR+ZTZfei2kkIssbE; AWSALBTGCORS=qZgepZq2iNqzI/cWNnAKBHv6qQNvEDQYbzdJs6cIbqhKfbfFM8GypnXrqH92HmKGpd7kbXgq8wyHjriS2RameqUTePW7wj70Ulvb0yrQC8hE2qq9sX/SDV0Jcv09jIUYiOmoe1P7YoqKve9EtJAJ0oIGXsvuR+ZTZfei2kkIssbE; PHPSESSID-FRONT=a8f7efe6df3a7bbaf6e2ab88f925df33' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Priority: u=0' \
--data-raw 'username=Kevin8407^&password=9vx03OSE'
curl 'https://sport.nubapp.com/web/ajax/bookings/checkBookings.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://sport.nubapp.com/web/index.php' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Origin: https://sport.nubapp.com' \
-H 'Sec-GPC: 1' \
-H 'Connection: keep-alive' \
-H 'Cookie: applicationId=81560887; AWSALBTG=qZgepZq2iNqzI/cWNnAKBHv6qQNvEDQYbzdJs6cIbqhKfbfFM8GypnXrqH92HmKGpd7kbXgq8wyHjriS2RameqUTePW7wj70Ulvb0yrQC8hE2qq9sX/SDV0Jcv09jIUYiOmoe1P7YoqKve9EtJAJ0oIGXsvuR+ZTZfei2kkIssbE; AWSALBTGCORS=qZgepZq2iNqzI/cWNnAKBHv6qQNvEDQYbzdJs6cIbqhKfbfFM8GypnXrqH92HmKGpd7kbXgq8wyHjriS2RameqUTePW7wj70Ulvb0yrQC8hE2qq9sX/SDV0Jcv09jIUYiOmoe1P7YoqKve9EtJAJ0oIGXsvuR+ZTZfei2kkIssbE; PHPSESSID-FRONT=a8f7efe6df3a7bbaf6e2ab88f925df33' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Priority: u=0' \
--data-raw 'items%5Bactivities%5D%5B0%5D%5Bid_activity_calendar%5D=18980977^&items%5Bactivities%5D%5B0%5D%5Bunit_price%5D=0^&items%5Bactivities%5D%5B0%5D%5Bn_guests%5D=0^&items%5Bactivities%5D%5B0%5D%5Bid_resource%5D=false^&discount_code=false'
curl 'https://sport.nubapp.com/api/v4/users/checkUser.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Nubapp-Origin: user_apps' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0' \
-H 'TE: trailers' \
--data-raw 'app_version=5.09.21^&device_type=3^&username=Kevin8407^&password=1dd67168'
curl 'https://sport.nubapp.com/api/v4/login' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Nubapp-Origin: user_apps' \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'TE: trailers' \
--data-raw 'device_type=3^&username=Kevin8407^&password=1dd67168'
curl 'https://sport.nubapp.com/api/v4/users/3191429/id_type_of_user' \
-X PUT \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NTEyOTM0NTYsImV4cCI6MTc2NzEwODI1Niwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImMwZmFiNGVlNDFjMGFkZGU5ODU1OTAxZGIxNjQ0YmEwZjk2ZDZhMGEiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.axAfZnzewEinSjnspgpO66tYJsbn1vAY6Dw-FivNjBZ4ylNWHQ1uWRbDAKYIhQMbQqcZ2_6HH_sa2YheIUA0fO2L276Qr9KZetGs_qwfn8AOkm63ALUQVKqwc-B6RGtmlE83m7gC5SgcPl6oNSoqV4k8lQ156V0Xr7E9fjcCNgjCJ8wFcHUp-XeVy54ixZHVxiLxFu1HHrlw0sisTwiQ7I3WAREn7XP7EwqFun9wwx8kyG1oggjShOecgiMX-68NIeJGwTcEBt2ssyKSRkibILw2p5BmABSmuYe_Hue4kYkyqvncBUJqMbpj8yeBKQUrT4undWPuYuWDftClClkM4A' \
-H 'Nubapp-Origin: user_apps' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0' \
-H 'TE: trailers' \
--data-raw 'app_version=5.09.21&id_type_of_user=1'
curl 'https://sport.nubapp.com/api/v4/users/changePassword.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-GB,en;q=0.8,fr-FR;q=0.5,fr;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NTEyOTM0NTYsImV4cCI6MTc2NzEwODI1Niwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImMwZmFiNGVlNDFjMGFkZGU5ODU1OTAxZGIxNjQ0YmEwZjk2ZDZhMGEiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.axAfZnzewEinSjnspgpO66tYJsbn1vAY6Dw-FivNjBZ4ylNWHQ1uWRbDAKYIhQMbQqcZ2_6HH_sa2YheIUA0fO2L276Qr9KZetGs_qwfn8AOkm63ALUQVKqwc-B6RGtmlE83m7gC5SgcPl6oNSoqV4k8lQ156V0Xr7E9fjcCNgjCJ8wFcHUp-XeVy54ixZHVxiLxFu1HHrlw0sisTwiQ7I3WAREn7XP7EwqFun9wwx8kyG1oggjShOecgiMX-68NIeJGwTcEBt2ssyKSRkibILw2p5BmABSmuYe_Hue4kYkyqvncBUJqMbpj8yeBKQUrT4undWPuYuWDftClClkM4A' \
-H 'Nubapp-Origin: user_apps' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0' \
-H 'TE: trailers' \
--data-raw 'app_version=5.09.21^&id_application=81560887^&id_user=3191429^&password=9vx03OSE^&old_password=1dd67168'
curl 'https://sport.nubapp.com/api/v4/users/getUsers.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: fr-FR,fr;q=0.8,en-GB;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NTEyOTM0NTYsImV4cCI6MTc2NzEwODI1Niwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImMwZmFiNGVlNDFjMGFkZGU5ODU1OTAxZGIxNjQ0YmEwZjk2ZDZhMGEiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.axAfZnzewEinSjnspgpO66tYJsbn1vAY6Dw-FivNjBZ4ylNWHQ1uWRbDAKYIhQMbQqcZ2_6HH_sa2YheIUA0fO2L276Qr9KZetGs_qwfn8AOkm63ALUQVKqwc-B6RGtmlE83m7gC5SgcPl6oNSoqV4k8lQ156V0Xr7E9fjcCNgjCJ8wFcHUp-XeVy54ixZHVxiLxFu1HHrlw0sisTwiQ7I3WAREn7XP7EwqFun9wwx8kyG1oggjShOecgiMX-68NIeJGwTcEBt2ssyKSRkibILw2p5BmABSmuYe_Hue4kYkyqvncBUJqMbpj8yeBKQUrT4undWPuYuWDftClClkM4A' \
-H 'Nubapp-Origin: user_apps' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0' \
-H 'TE: trailers' \
--data-raw 'app_version=5.09.21'
# Rejoindre la liste d'attente
curl 'https://sport.nubapp.com/api/v4/activities/bookWaitingActivityCalendar.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-GB,en;q=0.8,fr-FR;q=0.5,fr;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Referer: https://box.resawod.com/' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NTEyOTQxMDYsImV4cCI6MTc2NzEwODkwNiwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImMwZmFiNGVlNDFjMGFkZGU5ODU1OTAxZGIxNjQ0YmEwZjk2ZDZhMGEiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.O5XhReqJkqOq1XLv-D_1nJE4hnPX7cyJXHEb_moJ2wV2JXVjbJ5yUf6Jvl0s4xVsN-oIcrvjK7ZmH82cWa2TevIpsaeqARjPpsxDbmWEQO5Cgo9ZHk_btEHJMsl0hMBEQ3uKDcALSxZQLPzDPFm9hdsObng3eKl96oCCZU-UqwkjDRPJPqAIIu3bNbf2okbB0KFMoYClWCvVMb9jV5MFY-OCfV8Eap140kIuZSTRmu9VfBSndcC5L5AN0tmDtSIwJRat3YWZQUbsDTkBSv1h1L72geJhw_yBGUUg7FJ06WJ2QbbuONmZmBcmTiololJCdOZ_3I-usDaL_TdoGnXapQ' \
-H 'Nubapp-Origin: user_apps' \
-H 'Origin: https://box.resawod.com' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0' \
-H 'TE: trailers' \
--data-raw 'app_version=5.09.21&id_application=81560887&id_activity_calendar=19113851&id_user=3191429&action_by=3191429'
curl 'https://sport.nubapp.com/web/ajax/users/checkUser.php' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-GB,en;q=0.8,fr-FR;q=0.5,fr;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H 'Connection: keep-alive' \
-H 'Cookie: applicationId=81560887; AWSALBTG=tdjfBXoHwnzTmQh0eDNuYHrW68ZQDdXa582yNdxiDUr+GEh2R+4Lx42mY6vO2d+fpQ5hdkoyamXmR6wcwUOALAarNyBKGRID8eW3/63w9f7fF1qMJB4Yq6jp/yv02dkzCw9W8lsDFnJAQ4XJOsq8oGyGVTGdS1Z5psXTHrO1qrfV; AWSALBTGCORS=tdjfBXoHwnzTmQh0eDNuYHrW68ZQDdXa582yNdxiDUr+GEh2R+4Lx42mY6vO2d+fpQ5hdkoyamXmR6wcwUOALAarNyBKGRID8eW3/63w9f7fF1qMJB4Yq6jp/yv02dkzCw9W8lsDFnJAQ4XJOsq8oGyGVTGdS1Z5psXTHrO1qrfV; PHPSESSID-FRONT=66ef232a6bd57e8f75128347e2b1e144' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-Site: none' \
-H 'Sec-Fetch-User: ?1' \
-H 'Priority: u=0, i' \
--data-raw 'username=Kevin8407&password=9vx03OSE'