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

Provide another way to upload all kinds of sport type of TCX file to … #666

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vensent
Copy link
Contributor

@Vensent Vensent commented Apr 22, 2024

1、Support not only running but also biking.

Copy link

vercel bot commented Apr 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
running-page ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 28, 2024 3:30pm

type = to_upload_dict.get(i)["type"].lower()
if type not in STRAVA_GARMIN_TYPE_DICT.values():
continue
strava_type = list(STRAVA_GARMIN_TYPE_DICT.keys())[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about storing a reverted dict first:

GARMIN_STRAVA_TYPE_DICT = {value: key for key, value in STRAVA_GARMIN_TYPE_DICT.items()}

and this 3 lines can be replace by

strava_type = GARMIN_STRAVA_TYPE_DICT[type]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

89ed833
Fixed here.

with open(file_name, "rb") as f:
try:
r = client.upload_activity(
activity_file=f, data_type=data_type, activity_type=type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how Strava determines the type if you just upload the file but don't specify the activity_type?
For example, if you upload a tcx with the type of hiking, what type would it be in Strava?

Copy link
Contributor Author

@Vensent Vensent Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. got the description in Stravalib API here:
       :param activity_type: (optional) case-insensitive type of activity.
                            possible values: ride, run, swim, workout, hike, walk,
                            nordicski, alpineski, backcountryski, iceskate, inlineskate,
                            kitesurf, rollerski, windsurf, workout, snowboard, snowshoe
                            Type detected from file overrides, uses athlete's default type if not specified
      :type activity_type: str
  1. I have performed a test on my pc, and the result is just like uploading failed without strong hint:
to load all tcx files maybe take some time
Access ok
Start syncing
.
Process finished with exit code 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked the documentation for the upload API, which states that it detects the sport type from the file. refer: https://developers.strava.com/docs/uploads/
image

  1. I have performed a test on my pc, and the result is just like uploading failed without strong hint:
to load all tcx files maybe take some time
Access ok
Start syncing
.
Process finished with exit code 0

A dot (.) in the console indicates an updated activity, and a plus (+) indicates a created activity. I'm guessing the file you uploaded was already synced to Strava.
Can you help me test the following steps:

  1. Export a TCX of an activity in a others type, such as hiking or cycling.
  2. Delete the activity in Strava (you can re-upload it with the exported TCX file).
  3. Upload it using utils.upload_file_to_strava with force_to_run = False
  4. Check the activity type uploaded to Strava. if the type is correct then I believe we can use this function instead of adding upload_file_to_strava_with_type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested the TCX format of 'Running' and 'Biking'. The result is just as you said, and the type which shows at Strava is correct.

So, It seems that this PR is no longer needed?
@ben-29



def get_to_generate_files(last_time):
"""
reuturn to values one dict for upload
return to values one dict for upload
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

try:
upload_file_to_strava(client, tcx_file, "tcx")
upload_file_to_strava_with_type(client, tcx_file, "tcx", strava_type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about reverting other changes and adding a force_to_run = False parameter here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about reverting other changes and adding a force_to_run = False parameter here instead?

Sounds fair. I will do it later.

@Vensent
Copy link
Contributor Author

Vensent commented Apr 28, 2024

Please have another look. Thx. @ben-29 @yihong0618

@@ -92,7 +92,7 @@ def get_strava_last_time(client, is_milliseconds=True):
return 0


def upload_file_to_strava(client, file_name, data_type, force_to_run=True):
def upload_file_to_strava(client, file_name, data_type, force_to_run=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default force_to_run shouldn't be changed here, as it will affect features like Garmin, Keep, and Nike.
Just change the param in tcx_to_strava_sync.

Or just keep this unchanged, since this repo is mainly for running.

I'll change the force_to_run=False in workouts_page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see

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

Successfully merging this pull request may close these issues.

3 participants