Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError when downloading activity due to NULL activityName #231

Open
ajamess opened this issue Jun 4, 2024 · 1 comment
Open

KeyError when downloading activity due to NULL activityName #231

ajamess opened this issue Jun 4, 2024 · 1 comment

Comments

@ajamess
Copy link

ajamess commented Jun 4, 2024

I had an activity that did not have a title by default which caused a KeyError. I resolved this by updating the activity in Garmin Connect manually, but I think the script could handle this scenario better.

The way this activity appeared in Garmin Connect was the title here was marked as "Untitled" in the blue circle. I have since given it a title (Treadmill Running, as in the screenshot) to address the script issue.

image

The behavior of the script when encountering an "untitled" activity like this is to throw a KeyError

python ./garmindb_cli.py --all --download --import --analyze

___Downloading All Data___

Getting activities: 'C:\Users\<redacted>\HealthData\FitFiles\Activities' (3000) temp C:\Users\<redacted>\AppData\Local\Temp\tmp2ktvw9dt

 66%|████████████████████████████████████████████▏                      | 1380/2095 [00:00<00:00, 18094.66activities/s]

Traceback (most recent call last):

  File "C:\users\<redacted>\appdata\roaming\Python\Python312\Scripts\garmindb_cli.py", line 368, in <module>
    main(sys.argv[1:])

  File "C:\users\<redacted>\appdata\roaming\Python\Python312\Scripts\garmindb_cli.py", line 349, in main
    download_data(args.overwrite, args.latest, args.stats)

  File "C:\users\<redacted>\appdata\roaming\Python\Python312\Scripts\garmindb_cli.py", line 125, in download_data
    download.get_activities(activities_dir, activity_count, overwite)

  File "C:\Users\<redacted>\AppData\Roaming\Python\Python312\site-packages\garmindb\download.py", line 246, in get_activities
    activity_name_str = conversions.printable(activity['activityName'])
                                              ~~~~~~~~^^^^^^^^^^^^^^^^

KeyError: 'activityName'

When "activityName" is NULL, like in my example, there is no Key to look up in the activity[] dictionary, so the script errors.

image

The fix was for me to run PDB and find the failing activity ID, then manually update the title in Garmin Connect so the script would no longer fail. I am not sure how the activity ended up with no name. It might be some corner case on the Garmin side, because out of 2095 activities I imported, only 1 of them had this problem.

I see a few potential fixes to this corner case:

  1. When activityName is NULL, fall back to the activity description as the activityName
  2. When activityName is NULL, fall back to the activity ID as the activityName
  3. When activityName is NULL, throw an exception with an error message instructing the user to navigate to "https://connect.garmin.com/modern/activity/" to manually update the title. This was my solution (see first screenshot).

Thanks for your hard work on this script! It's very cool.

@ajamess
Copy link
Author

ajamess commented Jun 4, 2024

I found another example of such a broken activity:

image

Turns out I had a few hundred of them. I was able to bulk update their titles to "Other" in the screenshot below. The broken ones show up as "untitled", which map to a NULL activity name. I think many old activities may have this problem. So it is likely worth fixing the issue for folks like me who have been using garmin watches for a long time. I have activities going back to 2011, and it appears the issue started with these names around the 2015 timeframe. Here are some examples:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant