feat: more debug logs
This commit is contained in:
@@ -145,10 +145,39 @@ class CrossFitBooker:
|
|||||||
if not self.auth_token or not self.user_id:
|
if not self.auth_token or not self.user_id:
|
||||||
logging.error("Authentication required - missing token or user ID")
|
logging.error("Authentication required - missing token or user ID")
|
||||||
return None
|
return None
|
||||||
data = {**self.mandatory_params, "id_user": self.user_id,
|
data = {
|
||||||
"start_timestamp": start_date.strftime("%d-%m-%Y"),
|
**self.mandatory_params,
|
||||||
"end_timestamp": end_date.strftime("%d-%m-%Y")}
|
"id_user": self.user_id,
|
||||||
|
"start_timestamp": start_date.strftime("%d-%m-%Y"),
|
||||||
|
"end_timestamp": end_date.strftime("%d-%m-%Y"),
|
||||||
|
}
|
||||||
|
logging.debug(f"[get_available_sessions] URL=https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php "
|
||||||
|
f"method=POST content_type=application/x-www-form-urlencoded "
|
||||||
|
f"keys={list(data.keys())} id_user_present={bool(self.user_id)}")
|
||||||
r = self._post("https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php", data)
|
r = self._post("https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php", data)
|
||||||
|
# Display available sessions in debug console
|
||||||
|
if r is not None:
|
||||||
|
success = r.get("success", False) if isinstance(r, dict) else None
|
||||||
|
count = 0
|
||||||
|
try:
|
||||||
|
if isinstance(r, dict):
|
||||||
|
activities = r.get("data", {}).get("activities_calendar", [])
|
||||||
|
count = len(activities) if isinstance(activities, list) else 0
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
logging.debug(f"[get_available_sessions] success={success} activities_count={count}")
|
||||||
|
# Log concise session summary to aid debugging
|
||||||
|
if success and count:
|
||||||
|
for s in r.get("data", {}).get("activities_calendar", [])[:50]:
|
||||||
|
try:
|
||||||
|
summary = self._fmt_session(s)
|
||||||
|
except Exception:
|
||||||
|
summary = f"{s.get('id_activity_calendar')} {s.get('name_activity')} at {s.get('start_timestamp')}"
|
||||||
|
logging.debug(f"[session] {summary}")
|
||||||
|
else:
|
||||||
|
logging.debug(f"[get_available_sessions] raw_response_preview={str(r)[:500]}")
|
||||||
|
else:
|
||||||
|
logging.debug("[get_available_sessions] No response (None) from API")
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def book_session(self, session_id: str) -> bool:
|
def book_session(self, session_id: str) -> bool:
|
||||||
@@ -227,27 +256,54 @@ class CrossFitBooker:
|
|||||||
sessions_to_book: List[Tuple[str, Dict[str, Any]]] = []
|
sessions_to_book: List[Tuple[str, Dict[str, Any]]] = []
|
||||||
upcoming_sessions: List[Dict[str, Any]] = []
|
upcoming_sessions: List[Dict[str, Any]] = []
|
||||||
found_preferred_sessions: List[Dict[str, Any]] = []
|
found_preferred_sessions: List[Dict[str, Any]] = []
|
||||||
|
|
||||||
|
# Debug: list all preferred sessions detected (bookable or not)
|
||||||
|
preferred_debug: List[str] = []
|
||||||
|
|
||||||
for s in activities:
|
for s in activities:
|
||||||
st = self._parse_local(s["start_timestamp"])
|
st = self._parse_local(s["start_timestamp"])
|
||||||
days_diff = (st.date() - current_time.date()).days
|
days_diff = (st.date() - current_time.date()).days
|
||||||
if not (0 <= days_diff <= 2): continue
|
if not (0 <= days_diff <= 2):
|
||||||
|
continue
|
||||||
|
|
||||||
|
is_preferred = self.matches_preferred_session(s, current_time)
|
||||||
|
if is_preferred:
|
||||||
|
# Collect concise summaries to debug output
|
||||||
|
try:
|
||||||
|
preferred_debug.append(self._fmt_session(s, st))
|
||||||
|
except Exception:
|
||||||
|
preferred_debug.append(f"{s.get('id_activity_calendar')} {s.get('name_activity')} at {s.get('start_timestamp')}")
|
||||||
|
|
||||||
if self.is_session_bookable(s, current_time):
|
if self.is_session_bookable(s, current_time):
|
||||||
if self.matches_preferred_session(s, current_time):
|
if is_preferred:
|
||||||
sessions_to_book.append(("Preferred", s)); found_preferred_sessions.append(s)
|
sessions_to_book.append(("Preferred", s))
|
||||||
else:
|
|
||||||
if self.matches_preferred_session(s, current_time):
|
|
||||||
found_preferred_sessions.append(s)
|
found_preferred_sessions.append(s)
|
||||||
if days_diff == 1: upcoming_sessions.append(s)
|
else:
|
||||||
|
if is_preferred:
|
||||||
|
found_preferred_sessions.append(s)
|
||||||
|
if days_diff == 1:
|
||||||
|
upcoming_sessions.append(s)
|
||||||
|
|
||||||
|
# Emit debug of preferred sessions
|
||||||
|
if preferred_debug:
|
||||||
|
logging.debug("[preferred_sessions] " + " | ".join(preferred_debug[:50]))
|
||||||
|
else:
|
||||||
|
logging.debug("[preferred_sessions] none found in window")
|
||||||
|
|
||||||
if not sessions_to_book and not upcoming_sessions:
|
if not sessions_to_book and not upcoming_sessions:
|
||||||
logging.info("No matching sessions found to book"); return
|
logging.info("No matching sessions found to book")
|
||||||
|
return
|
||||||
|
|
||||||
for s in found_preferred_sessions:
|
for s in found_preferred_sessions:
|
||||||
details = self._fmt_session(s)
|
details = self._fmt_session(s)
|
||||||
await self.notifier.notify_session_booking(details)
|
await self.notifier.notify_session_booking(details)
|
||||||
logging.info(f"Notified about found preferred session: {details}")
|
logging.info(f"Notified about found preferred session: {details}")
|
||||||
|
|
||||||
for s in upcoming_sessions:
|
for s in upcoming_sessions:
|
||||||
details = self._fmt_session(s)
|
details = self._fmt_session(s)
|
||||||
await self.notifier.notify_upcoming_session(details, 1)
|
await self.notifier.notify_upcoming_session(details, 1)
|
||||||
logging.info(f"Notified about upcoming session: {details}")
|
logging.info(f"Notified about upcoming session: {details}")
|
||||||
|
|
||||||
sessions_to_book.sort(key=lambda x: 0 if x[0] == "Preferred" else 1)
|
sessions_to_book.sort(key=lambda x: 0 if x[0] == "Preferred" else 1)
|
||||||
for stype, s in sessions_to_book:
|
for stype, s in sessions_to_book:
|
||||||
st_dt = datetime.strptime(s["start_timestamp"], "%Y-%m-%d %H:%M:%S")
|
st_dt = datetime.strptime(s["start_timestamp"], "%Y-%m-%d %H:%M:%S")
|
||||||
|
|||||||
Reference in New Issue
Block a user