diff --git a/book_crossfit.py b/book_crossfit.py index d913829..3746858 100755 --- a/book_crossfit.py +++ b/book_crossfit.py @@ -216,32 +216,58 @@ class CrossFitBooker: return None def book_session(self, session_id: str) -> bool: - """Book a specific session""" + """Book a specific session with debug logging.""" + print(f"\n[INFO] Attempting to book session_id: {session_id}") if not self.auth_token or not self.user_id: - print("Not authenticated") + print("[ERROR] Not authenticated (missing auth_token or user_id)") return False try: - # Prepare request with mandatory parameters + # Prepare headers + headers = self.get_auth_headers() + + # print(f"[DEBUG] Request headers: {headers}") + + # Prepare the exact request data from cURL request_data = self.mandatory_params.copy() request_data.update({ + "id_activity_calendar": session_id, # Note the different parameter name "id_user": self.user_id, - "id_activity": session_id + "action_by": self.user_id, # Same as id_user in this case + "n_guests": "0", + "booked_on": "3" # 3 likely means "booked via app" }) + print(f"[DEBUG] Final request data: {request_data}") + + # Use the correct endpoint response = self.session.post( - "https://sport.nubapp.com/api/v4/activities/bookActivity.php", - headers=self.get_auth_headers(), - data=urlencode(request_data)) + "https://sport.nubapp.com/api/v4/activities/bookActivityCalendar.php", + headers=headers, + data=urlencode(request_data) + ) + + print(f"[DEBUG] Response status: {response.status_code}") + print(f"[DEBUG] Response text: {response.text}") if response.ok: - print(f"Successfully booked session {session_id}") - return True + try: + json_response = response.json() + if json_response.get("success", False): + print(f"[SUCCESS] Booked session {session_id}") + return True + else: + print(f"[ERROR] API returned success:false: {json_response}") + return False + except ValueError: + print("[ERROR] Invalid JSON response") + return False else: - print(f"Error booking session {session_id}: {response.status_code} - {response.text}") + print(f"[ERROR] HTTP {response.status_code}: {response.text}") return False + except Exception as e: - print(f"Error booking session: {str(e)}") + print(f"[CRITICAL] Unexpected error: {str(e)}", exc_info=True) return False def is_session_bookable(self, session: Dict, current_time: datetime) -> bool: @@ -397,7 +423,9 @@ if __name__ == "__main__": for session in bookable_sessions: - result = booker.matches_preferred_session(session, current_time) - print(session.get("name_activity") + " / " + str(result)) + is_prefered_session = booker.matches_preferred_session(session, current_time) + # print(session.get("name_activity") + " / " + str(is_prefered_session)) + if is_prefered_session: + booker.book_session(session.get("id_activity_calendar")) diff --git a/crossfit.txt b/crossfit.txt index b6fb432..83703b8 100644 --- a/crossfit.txt +++ b/crossfit.txt @@ -77,4 +77,24 @@ Book activity -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=19291336&id_user=3191429&action_by=3191429&n_guests=0&booked_on=3' \ No newline at end of file + --data-raw 'app_version=5.09.21&id_application=81560887^&id_activity_calendar=19291336&id_user=3191429&action_by=3191429&n_guests=0&booked_on=3' + + curl 'https://sport.nubapp.com/api/v4/activities/bookActivityCalendar.php' \ + -X POST \ + -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.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.eyJpYXQiOjE3NTI4MjQ5NjcsImV4cCI6MTc2ODcyNjE2Nywicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImEzZGZiOGQzY2NhNTA5NmJhYzYxMWM4MmEwMzYyYTg2ODc3MjQ4MjIiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.OMw1ziZHctxqeBYXyMag-XPnok5Ec4QoVyPrmiUIH6HsEl1WLvpsC-FfkYrQ4dvRqy2MO7ZOOoUf8CL1D2GpcaGke3nYDmQ8d7FDn_veL0vRYhZ6-AGJfDJ4O5pc_ZjjspF8CkpKEHvZLeQfIHzvbU79mjDzXsIjZzD00pBBt4sECrPaHArPvQI77ES7r_q5spitHTUy3Jeeir5bax3gMWUu6ru5dWciG0L3_tTMauTUVw68eS-nxWH4oxYPkfkt8UrQ3Xqh3Ezm3I06zD174iy0fY20XCx34SvjaP3rU3rELApDKZaWYrpBjSdBgXAz27TPfP4ZajnArjQzkjTgDw' \ + -H 'Nubapp-Origin: user_apps' \ + -H 'Origin: https://box.resawod.com' \ + -H 'Sec-GPC: 1' \ + -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=19291321&id_user=3191429&action_by=3191429&n_guests=0&booked_on=3' \ No newline at end of file