Skip to content

Commit

Permalink
fix: strava to garmin sync
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong0618 committed Oct 10, 2023
1 parent e4a2cb6 commit a0d6ed5
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions run_page/garmin_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"MODERN_URL": "https://connectapi.garmin.com",
"SIGNIN_URL": "https://sso.garmin.com/sso/signin",
"CSS_URL": "https://static.garmincdn.com/com.garmin.connect/ui/css/gauth-custom-v1.2-min.css",
"UPLOAD_URL": "https://connectapi.garmin.com/upload-service/upload/.gpx",
"UPLOAD_URL": "https://connectapi.garmin.com/upload-service/upload/",
"ACTIVITY_URL": "https://connectapi.garmin.com/activity-service/activity/{activity_id}",
}

Expand All @@ -45,7 +45,7 @@
"MODERN_URL": "https://connectapi.garmin.cn",
"SIGNIN_URL": "https://sso.garmin.cn/sso/signin",
"CSS_URL": "https://static.garmincdn.cn/cn.garmin.connect/ui/css/gauth-custom-v1.2-min.css",
"UPLOAD_URL": "https://connectapi.garmin.cn/upload-service/upload/.gpx",
"UPLOAD_URL": "https://connectapi.garmin.cn/upload-service/upload/",
"ACTIVITY_URL": "https://connectapi.garmin.cn/activity-service/activity/{activity_id}",
}

Expand Down Expand Up @@ -123,39 +123,9 @@ async def download_activity(self, activity_id, file_type="gpx"):
response.raise_for_status()
return response.read()

async def upload_activities(self, files):
for file, garmin_type in files:
files = {"data": ("file.gpx", file)}
try:
res = await self.req.post(
self.upload_url, files=files, headers={"nk": "NT"}
)
except Exception as e:
print(str(e))
# just pass for now
continue
try:
resp = res.json()["detailedImportResult"]
except Exception as e:
print(e)
raise Exception("failed to upload")
# change the type
if resp["successes"]:
activity_id = resp["successes"][0]["internalId"]
print(f"id {activity_id} uploaded...")
data = {"activityTypeDTO": {"typeKey": garmin_type}}
encoding_headers = {"Content-Type": "application/json; charset=UTF-8"}
r = await self.req.put(
self.activity_url.format(activity_id=activity_id),
data=json.dumps(data),
headers=encoding_headers,
)
r.raise_for_status()
await self.req.aclose()

async def upload_activities_original(self, datas, use_fake_garmin_device=False):
print(
"start upload activities to garmin!!!, use_fake_garmin_device:",
"start upload activities to garmin!, use_fake_garmin_device:",
use_fake_garmin_device,
)
for data in datas:
Expand All @@ -169,7 +139,7 @@ async def upload_activities_original(self, datas, use_fake_garmin_device=False):
file_body = wrap_device_info(f)
else:
file_body = BytesIO(f.read())
files = {"data": (data.filename, file_body)}
files = {"file": (data.filename, file_body)}

try:
res = await self.req.post(
Expand Down

1 comment on commit a0d6ed5

@vercel
Copy link

@vercel vercel bot commented on a0d6ed5 Oct 10, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

running-page – ./

running-page-yihong0618.vercel.app
running-page-git-master-yihong0618.vercel.app
running-page.vercel.app

Please sign in to comment.