improved version from Deepseek
This commit is contained in:
@@ -32,40 +32,54 @@ class CrossFitBooker:
|
|||||||
self.auth_token = None
|
self.auth_token = None
|
||||||
self.user_id = None
|
self.user_id = None
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.headers.update({
|
self.base_headers = {
|
||||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0",
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0",
|
||||||
"Accept": "application/json, text/plain, */*",
|
"Accept": "application/json, text/plain, */*",
|
||||||
"Accept-Language": "en-GB,en;q=0.8,fr-FR;q=0.5,fr;q=0.3",
|
"Accept-Language": "en-GB,en;q=0.8,fr-FR;q=0.5,fr;q=0.3",
|
||||||
"Nubapp-Origin": "user_apps",
|
"Nubapp-Origin": "user_apps",
|
||||||
"Origin": "https://box.resawod.com",
|
"Origin": "https://box.resawod.com",
|
||||||
"Referer": "https://box.resawod.com/",
|
"Referer": "https://box.resawod.com/",
|
||||||
})
|
}
|
||||||
|
self.session.headers.update(self.base_headers)
|
||||||
|
|
||||||
|
# Define mandatory parameters for API calls
|
||||||
|
self.mandatory_params = {
|
||||||
|
"app_version": APP_VERSION,
|
||||||
|
"device_type": DEVICE_TYPE,
|
||||||
|
"id_application": APPLICATION_ID,
|
||||||
|
"id_category_activity": CATEGORY_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_auth_headers(self) -> Dict:
|
||||||
|
"""Return headers with authorization if available"""
|
||||||
|
headers = self.base_headers.copy()
|
||||||
|
if self.auth_token:
|
||||||
|
headers["Authorization"] = f"Bearer {self.auth_token}"
|
||||||
|
return headers
|
||||||
|
|
||||||
def login(self) -> bool:
|
def login(self) -> bool:
|
||||||
"""Authenticate and get the bearer token"""
|
"""Authenticate and get the bearer token"""
|
||||||
try:
|
try:
|
||||||
# First login endpoint
|
# First login endpoint
|
||||||
|
login_params = {
|
||||||
|
"app_version": APP_VERSION,
|
||||||
|
"device_type": DEVICE_TYPE,
|
||||||
|
"username": USERNAME,
|
||||||
|
"password": PASSWORD
|
||||||
|
}
|
||||||
|
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
"https://sport.nubapp.com/api/v4/users/checkUser.php",
|
"https://sport.nubapp.com/api/v4/users/checkUser.php",
|
||||||
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
||||||
data=urlencode({
|
data=urlencode(login_params))
|
||||||
"app_version": APP_VERSION,
|
|
||||||
"device_type": DEVICE_TYPE,
|
|
||||||
"username": USERNAME,
|
|
||||||
"password": PASSWORD
|
|
||||||
}))
|
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(f"First login step failed: {response.status_code} - {response.text}")
|
print(f"First login step failed: {response.status_code} - {response.text}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
login_data = response.json()
|
login_data = response.json()
|
||||||
# self.auth_token = login_data["data"]["token"]
|
|
||||||
self.user_id = str(login_data["data"]["user"]["id_user"])
|
self.user_id = str(login_data["data"]["user"]["id_user"])
|
||||||
|
|
||||||
# Uncomment to see user_id
|
|
||||||
# print(self.user_id)
|
|
||||||
|
|
||||||
# Second login endpoint
|
# Second login endpoint
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
"https://sport.nubapp.com/api/v4/login",
|
"https://sport.nubapp.com/api/v4/login",
|
||||||
@@ -76,14 +90,10 @@ class CrossFitBooker:
|
|||||||
"password": PASSWORD
|
"password": PASSWORD
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
login_data = response.json()
|
login_data = response.json()
|
||||||
self.auth_token = login_data.get("token")
|
self.auth_token = login_data.get("token")
|
||||||
|
|
||||||
# Uncomment to see Bearer token
|
|
||||||
# print(self.auth_token)
|
|
||||||
|
|
||||||
if self.auth_token and self.user_id:
|
if self.auth_token and self.user_id:
|
||||||
print("Successfully logged in")
|
print("Successfully logged in")
|
||||||
return True
|
return True
|
||||||
@@ -102,34 +112,25 @@ class CrossFitBooker:
|
|||||||
|
|
||||||
url = "https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php"
|
url = "https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php"
|
||||||
|
|
||||||
# Prepare request components
|
# Prepare request with mandatory parameters
|
||||||
headers = {
|
request_data = self.mandatory_params.copy()
|
||||||
"Authorization": f"Bearer {self.auth_token}",
|
request_data.update({
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0",
|
|
||||||
"Nubapp-Origin": "user_apps"
|
|
||||||
}
|
|
||||||
|
|
||||||
request_data = {
|
|
||||||
"app_version": APP_VERSION,
|
|
||||||
"id_application": APPLICATION_ID,
|
|
||||||
"id_user": self.user_id,
|
"id_user": self.user_id,
|
||||||
"start_timestamp": start_date.strftime("%d-%m-%Y"),
|
"start_timestamp": start_date.strftime("%d-%m-%Y"),
|
||||||
"end_timestamp": end_date.strftime("%d-%m-%Y"),
|
"end_timestamp": end_date.strftime("%d-%m-%Y")
|
||||||
"id_category_activity": CATEGORY_ID
|
})
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Debug output
|
# Debug output
|
||||||
print("\n--- Request Details ---")
|
print("\n--- Request Details ---")
|
||||||
print(f"URL: {url}")
|
print(f"URL: {url}")
|
||||||
print(f"Headers: {json.dumps(headers, indent=2)}")
|
print(f"Headers: {json.dumps(self.get_auth_headers(), indent=2)}")
|
||||||
print(f"Payload: {request_data}")
|
print(f"Payload: {request_data}")
|
||||||
|
|
||||||
# Make the request
|
# Make the request
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
url,
|
url,
|
||||||
headers=headers,
|
headers=self.get_auth_headers(),
|
||||||
data=urlencode(request_data),
|
data=urlencode(request_data),
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
@@ -155,11 +156,8 @@ class CrossFitBooker:
|
|||||||
elif response.status_code == 400:
|
elif response.status_code == 400:
|
||||||
print("400 Bad Request - likely missing or invalid parameters")
|
print("400 Bad Request - likely missing or invalid parameters")
|
||||||
print("Verify these parameters:")
|
print("Verify these parameters:")
|
||||||
print(f"- app_version: {APP_VERSION}")
|
for param, value in request_data.items():
|
||||||
print(f"- id_application: {APPLICATION_ID}")
|
print(f"- {param}: {value}")
|
||||||
print(f"- id_user: {self.user_id}")
|
|
||||||
print(f"- Date format (DD-MM-YYYY): {start_date.strftime('%d-%m-%Y')} to {end_date.strftime('%d-%m-%Y')}")
|
|
||||||
print(f"- id_category_activity: {CATEGORY_ID}")
|
|
||||||
return None
|
return None
|
||||||
elif response.status_code == 401:
|
elif response.status_code == 401:
|
||||||
print("401 Unauthorized - token may be expired or invalid")
|
print("401 Unauthorized - token may be expired or invalid")
|
||||||
@@ -182,15 +180,17 @@ class CrossFitBooker:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Prepare request with mandatory parameters
|
||||||
|
request_data = self.mandatory_params.copy()
|
||||||
|
request_data.update({
|
||||||
|
"id_user": self.user_id,
|
||||||
|
"id_activity": session_id
|
||||||
|
})
|
||||||
|
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
"https://sport.nubapp.com/api/v4/activities/bookActivity.php",
|
"https://sport.nubapp.com/api/v4/activities/bookActivity.php",
|
||||||
headers={"Authorization": f"Bearer {self.auth_token}"},
|
headers=self.get_auth_headers(),
|
||||||
data=urlencode({
|
data=urlencode(request_data))
|
||||||
"app_version": APP_VERSION,
|
|
||||||
"id_application": APPLICATION_ID,
|
|
||||||
"id_user": self.user_id,
|
|
||||||
"id_activity": session_id
|
|
||||||
}))
|
|
||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
print(f"Successfully booked session {session_id}")
|
print(f"Successfully booked session {session_id}")
|
||||||
@@ -319,5 +319,5 @@ if __name__ == "__main__":
|
|||||||
booker.login()
|
booker.login()
|
||||||
sessions = booker.get_available_sessions(datetime.strptime("21-07-2025", "%d-%m-%Y"), datetime.strptime("27-07-2025", "%d-%m-%Y"))
|
sessions = booker.get_available_sessions(datetime.strptime("21-07-2025", "%d-%m-%Y"), datetime.strptime("27-07-2025", "%d-%m-%Y"))
|
||||||
# print(sessions)
|
# print(sessions)
|
||||||
booker.run_booking_cycle(datetime.now())
|
# booker.run_booking_cycle(datetime.now())
|
||||||
# booker.run()
|
# booker.run()
|
||||||
Reference in New Issue
Block a user