Skip to content

Commit

Permalink
Merge branch 'yihong0618:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jujimeizuo authored Oct 11, 2023
2 parents 9124c55 + be1cefe commit b422369
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 60 deletions.
2 changes: 2 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
| [EINDEX](https://github.com/eindex) | <https://workouts.eindex.me/> | Strava/Nike |
| [Melt](https://github.com/fpGHwd) | <https://running.autove.dev/> | Strava |
| [deepinwine](https://github.com/deepinwine) | <https://deepin.autove.dev/> | Garmin-cn |
| [Jeffggmm](https://github.com/Jeffggmm) | <https://jeffggmm.github.io/workouts_page/> | Garmin |

</details>

Expand Down Expand Up @@ -880,6 +881,7 @@ Actions [源码](https://github.com/yihong0618/running_page/blob/master/.github/
```shell
curl https://api.github.com/repos/yihong0618/running_page/actions/workflows -H "Authorization: token d8xxxxxxxxxx" # change to your config
```

<center><img src="https://cdn.jujimeizuo.cn/blog/2023/10/get-action-id.jpg" alt="get-action-id"></center>

2. 结合快捷指令
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/
| [Melt](https://github.com/fpGHwd) | <https://running.autove.dev/> | Strava |
| [deepinwine](https://github.com/deepinwine) | <https://deepin.autove.dev/> | Garmin-cn |
| [Echo](https://github.com/donghao526) | <https://donghao526.github.io/running> | JoyRun |
| [Jeffggmm](https://github.com/Jeffggmm) | <https://jeffggmm.github.io/workouts_page/> | Garmin |

</details>

Expand Down Expand Up @@ -736,26 +737,26 @@ Take the keep app as an example. Close the app after running, and then automatic
```shell
curl https://api.github.com/repos/yihong0618/running_page/actions/workflows -H "Authorization: token d8xxxxxxxxxx" # change to your config
```

<center><img src="https://cdn.jujimeizuo.cn/blog/2023/10/get-action-id.jpg" alt="get-action-id"></center>

2. Binding shortcut instruction

1. Get it via icloud [running-page-shortcuts-template](https://www.icloud.com/shortcuts/4a5807a98b9a4e359815ff179c62bacb)
2. Modify the dictionary parameters in the following figure
1. Get it via icloud [running-page-shortcuts-template](https://www.icloud.com/shortcuts/4a5807a98b9a4e359815ff179c62bacb)

2. Modify the dictionary parameters in the following figure
<center> <img src="https://cdn.jujimeizuo.cn/blog/2023/10/running-page-template.jpg"> </center>

3. Automation

<center>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/new-automation.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/select-close.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/select-shortcut.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/finish-automation.png" width=20% height=20%>
</center>

</details>
<center>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/new-automation.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/select-close.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/select-shortcut.png" width=20% height=20%>
<img src="https://cdn.jujimeizuo.cn/blog/2023/10/finish-automation.png" width=20% height=20%>
</center>

</details>

## Storing Data Files in GitHub Cache

Expand Down
46 changes: 5 additions & 41 deletions run_page/garmin_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import argparse
import asyncio
import json
import logging
import os
import sys
Expand All @@ -27,25 +26,20 @@

TIME_OUT = httpx.Timeout(240.0, connect=360.0)
GARMIN_COM_URL_DICT = {
"BASE_URL": "https://connectapi.garmin.com",
"SSO_URL_ORIGIN": "https://sso.garmin.com",
"SSO_URL": "https://sso.garmin.com/sso",
# "MODERN_URL": "https://connect.garmin.com/modern",
"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}",
}

GARMIN_CN_URL_DICT = {
"BASE_URL": "https://connectapi.garmin.cn",
"SSO_URL_ORIGIN": "https://sso.garmin.com",
"SSO_URL": "https://sso.garmin.cn/sso",
"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 +117,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,11 +133,11 @@ 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(
self.upload_url, files=files, headers={"nk": "NT"}
self.upload_url, files=files, headers=self.headers
)
os.remove(data.filename)
f.close()
Expand Down
8 changes: 0 additions & 8 deletions v2.0_TODO.md

This file was deleted.

0 comments on commit b422369

Please sign in to comment.