feat: Booking activity done
This commit is contained in:
@@ -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"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user