feat(sessions): Retrieve all available courses from API
This commit is contained in:
64
retrieve_sessions.py
Executable file
64
retrieve_sessions.py
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from urllib.parse import urlencode
|
||||
import json
|
||||
|
||||
def get_crossfit_sessions(auth_token, user_id, start_date, end_date):
|
||||
"""Fetch CrossFit sessions with proper error handling"""
|
||||
url = "https://sport.nubapp.com/api/v4/activities/getActivitiesCalendar.php"
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0",
|
||||
"Authorization": f"Bearer {auth_token}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Nubapp-Origin": "user_apps"
|
||||
}
|
||||
|
||||
params = {
|
||||
"app_version": "5.09.21",
|
||||
"id_application": "81560887",
|
||||
"id_user": user_id,
|
||||
"start_timestamp": start_date.strftime("%d-%m-%Y"),
|
||||
"end_timestamp": end_date.strftime("%d-%m-%Y"),
|
||||
"id_category_activity": "677"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
url,
|
||||
headers=headers,
|
||||
data=urlencode(params),
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
print(f"API Error: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Request failed: {str(e)}")
|
||||
return None
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
# Replace with your actual token and user ID
|
||||
AUTH_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NTI3NjE3OTMsImV4cCI6MTc2ODY2Mjk5Mywicm9sZXMiOlsiUk9MRV9VU0VSIl0sImlkX3VzZXIiOjMxOTE0MjksImlkX2FwcGxpY2F0aW9uIjo4MTU2MDg4NywicGFzc3dvcmRfaGFzaCI6ImEzZGZiOGQzY2NhNTA5NmJhYzYxMWM4MmEwMzYyYTg2ODc3MjQ4MjIiLCJhdXRoZW50aWNhdGlvbl90eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJLZXZpbjg0MDcifQ.l3NmfHISvrErpYMPBR-nvBT1ijOnDLFLgBUr9icg-WVwpA4ff1IXUd4kSJCP2pxj8ziG8eNpLitHFQGp27-b_cdb6f5usSH4tysWHRD__M4o_htYbSAD1qJcw1kwSRw4ZWGCoLqh8c8SGd5LK3ZmddSv3ECx3BK7CvyZggDfeSDK-hDCyJejWi6L3UeV49_aa5a49Ll6Kb6GvOZVzIuU8xikbpsIrLStOo26sNjW-_2dw2gvBUuDz6InGTvUHIJgfvR2s6RlyUH8imyprsv8hFHP-oeqmIXYdvKi9FH4v8EAsmYfENcx4NHJHHck8y8EeS2e3kOO1HyWLPURQDBppA"
|
||||
USER_ID = "3191429"
|
||||
|
||||
# Set date range (today + 7 days)
|
||||
start_date = datetime.now()
|
||||
end_date = start_date + timedelta(days=7)
|
||||
|
||||
sessions = get_crossfit_sessions(AUTH_TOKEN, USER_ID, start_date, end_date)
|
||||
|
||||
if sessions and sessions.get("success"):
|
||||
print("Successfully retrieved sessions:")
|
||||
print(json.dumps(sessions, indent=2))
|
||||
else:
|
||||
print("Failed to retrieve sessions")
|
||||
if sessions:
|
||||
print(f"API Message: {sessions.get('message')}")
|
||||
Reference in New Issue
Block a user