1010import json
1111import os
1212import sys
13- from datetime import datetime , timedelta , timezone
14-
1513import httpx
1614
1715from playerdatapy .constants import API_BASE_URL
1816from playerdatapy .gqlauth import AuthenticationType
1917from playerdatapy .playerdata_api import PlayerDataAPI
2018
21- from queries .club_sessions_filtered_by_time_range import (
22- club_sessions_filtered_by_time_range ,
23- )
24- from queries .session_ball_data import session_ball_data
19+ from examples .pydantic .queries .club_sessions import club_sessions
20+ from examples .pydantic .queries .session_ball_data import session_ball_data
2521
2622# -----------------------------------------------------------------------------
2723# Config (env or override below)
2824# -----------------------------------------------------------------------------
2925CLIENT_ID = os .environ .get ("CLIENT_ID" )
3026CLUB_ID = os .environ .get ("CLUB_ID" )
31- SESSION_DAYS = 30 # sessions from last N days
3227
3328
3429def _record_count (data : list | dict ) -> int :
@@ -84,6 +79,9 @@ async def download_recording(
8479 """Download one recording's raw JSON to out_dir. Returns True if saved, False if skipped."""
8580 url = recording .get ("url" )
8681 if not url :
82+ ball = recording .get ("ball" ) or {}
83+ serial = ball .get ("serialNumber" , "?" )
84+ print (f" Skip { recording ['id' ]} (Ball { serial } ): no URL" )
8785 return False
8886 if url .startswith ("/" ):
8987 url = f"{ API_BASE_URL .rstrip ('/' )} { url } "
@@ -99,7 +97,8 @@ async def download_recording(
9997 print (f" Skip { recording ['id' ]} (Ball { serial } ): { e .response .status_code } " )
10098 return False
10199 except httpx .RequestError as e :
102- print (f" Skip { recording ['id' ]} (Ball { serial } ): { e } " )
100+ reason = str (e ).strip () or type (e ).__name__
101+ print (f" Skip { recording ['id' ]} (Ball { serial } ): { reason } " )
103102 return False
104103
105104 if _record_count (raw ) == 0 :
@@ -120,23 +119,16 @@ async def main() -> None:
120119 authentication_type = AuthenticationType .AUTHORISATION_CODE_FLOW_PCKE ,
121120 )
122121
123- now = datetime .now (timezone .utc )
124- start = now - timedelta (days = SESSION_DAYS )
125-
126122 sessions_response = await api .run_queries (
127- "ClubSessionsFilteredByTimeRangeQuery" ,
128- club_sessions_filtered_by_time_range (
129- club_id = CLUB_ID ,
130- start_time_gteq = start ,
131- end_time_lteq = now ,
132- ),
123+ "ClubSessionsQuery" ,
124+ club_sessions (club_id = CLUB_ID ),
133125 )
134126 sessions = sessions_response .get ("sessions" ) or []
135127
136128 if not sessions :
137129 print ("No sessions found." )
138130 return
139- print (f"Found { len (sessions )} session(s) in last { SESSION_DAYS } days ." )
131+ print (f"Found { len (sessions )} session(s)." )
140132
141133 chosen = _choose_session (sessions )
142134 if not chosen :
@@ -165,7 +157,7 @@ async def main() -> None:
165157 print (f"Downloading { len (recordings_with_url )} recording(s) to { out_dir } /" )
166158
167159 headers = {"Authorization" : f"Bearer { api ._get_authentication_token ()} " }
168- async with httpx .AsyncClient (headers = headers ) as http_client :
160+ async with httpx .AsyncClient (headers = headers , timeout = 60.0 ) as http_client :
169161 ok = sum (
170162 await asyncio .gather (
171163 * [
0 commit comments