@@ -70,9 +70,7 @@ def __init__(self):
7070
7171 # Activity settings
7272 self .activitytype = "" # Possible values: cycling, running, swimming, multi_sport, fitness_equipment, hiking, walking, other
73- self .activityfile = (
74- "test_data/sample_activity.gpx" # Supported file types: .fit .gpx .tcx
75- )
73+ self .activityfile = "test_data/*.gpx" # Supported file types: .fit .gpx .tcx
7674 self .workoutfile = "test_data/sample_workout.json" # Sample workout JSON file
7775
7876 # Export settings
@@ -1288,37 +1286,52 @@ def get_solar_data(api: Garmin) -> None:
12881286
12891287def upload_activity_file (api : Garmin ) -> None :
12901288 """Upload activity data from file."""
1289+ import glob
1290+ import os
1291+
12911292 try :
1292- # Default activity file from config
1293- print (f"📤 Uploading activity from file: { config .activityfile } " )
1293+ # List all .gpx files in test_data
1294+ gpx_files = glob .glob ("test_data/*.gpx" )
1295+ if not gpx_files :
1296+ print ("❌ No .gpx files found in test_data directory." )
1297+ print ("ℹ️ Please add GPX files to test_data before uploading." )
1298+ return
12941299
1295- # Check if file exists
1296- import os
1300+ print ("Select a GPX file to upload:" )
1301+ for idx , fname in enumerate (gpx_files , 1 ):
1302+ print (f" { idx } . { fname } " )
12971303
1298- if not os .path .exists (config .activityfile ):
1299- print (f"❌ File not found: { config .activityfile } " )
1300- print (
1301- "ℹ️ Please place your activity file (.fit, .gpx, or .tcx) under the 'test_data' directory or update config.activityfile"
1302- )
1303- print ("ℹ️ Supported formats: FIT, GPX, TCX" )
1304+ while True :
1305+ try :
1306+ choice = int (input (f"Enter number (1-{ len (gpx_files )} ): " ))
1307+ if 1 <= choice <= len (gpx_files ):
1308+ selected_file = gpx_files [choice - 1 ]
1309+ break
1310+ else :
1311+ print ("Invalid selection. Try again." )
1312+ except ValueError :
1313+ print ("Please enter a valid number." )
1314+
1315+ print (f"📤 Uploading activity from file: { selected_file } " )
1316+ if not os .path .exists (selected_file ):
1317+ print (f"❌ File not found: { selected_file } " )
13041318 return
13051319
1306- # Upload the activity
1307- result = api .upload_activity (config .activityfile )
1320+ result = api .upload_activity (selected_file )
13081321
13091322 if result :
13101323 print ("✅ Activity uploaded successfully!" )
13111324 call_and_display (
13121325 api .upload_activity ,
1313- config . activityfile ,
1326+ selected_file ,
13141327 method_name = "upload_activity" ,
1315- api_call_desc = f"api.upload_activity({ config . activityfile } )" ,
1328+ api_call_desc = f"api.upload_activity({ selected_file } )" ,
13161329 )
13171330 else :
1318- print (f"❌ Failed to upload activity from { config . activityfile } " )
1331+ print (f"❌ Failed to upload activity from { selected_file } " )
13191332
13201333 except FileNotFoundError :
1321- print (f"❌ File not found: { config . activityfile } " )
1334+ print (f"❌ File not found: { selected_file } " )
13221335 print ("ℹ️ Please ensure the activity file exists in the current directory" )
13231336 except requests .exceptions .HTTPError as e :
13241337 if e .response .status_code == 409 :
@@ -1363,7 +1376,6 @@ def upload_activity_file(api: Garmin) -> None:
13631376 print (f"❌ Too many requests: { e } " )
13641377 print ("💡 Please wait a few minutes before trying again" )
13651378 except Exception as e :
1366- # Check if this is a wrapped HTTP error from the Garmin library
13671379 error_str = str (e )
13681380 if "409 Client Error: Conflict" in error_str :
13691381 print (
0 commit comments