From e4a2cb6d640460f6f6f7592debe737c093e09633 Mon Sep 17 00:00:00 2001 From: Zetao Feng Date: Tue, 10 Oct 2023 14:21:04 +0800 Subject: [PATCH 1/2] feat: add IOS Shortcuts in README (#513) --- README-CN.md | 33 +++++++++++++++++++++++++++++++++ README.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/README-CN.md b/README-CN.md index 4fcb97a1ffb..e3bf2942207 100644 --- a/README-CN.md +++ b/README-CN.md @@ -867,6 +867,39 @@ Actions [源码](https://github.com/yihong0618/running_page/blob/master/.github/ +## 快捷指令 + +
+ +使用 iOS 的 Shortcuts 实现自动化 + +下面拿 keep app 举例,当结束跑步后关闭 app,然后自动触发 Actions 更新数据。 + +1. 拿到项目的 actions id(需要自行申请 token) + +```shell +curl https://api.github.com/repos/yihong0618/running_page/actions/workflows -H "Authorization: token d8xxxxxxxxxx" # change to your config +``` +
get-action-id
+ +2. 结合快捷指令 + + 1. 通过 icloud 获取 [running-page-shortcuts-template](https://www.icloud.com/shortcuts/4a5807a98b9a4e359815ff179c62bacb) + + 2. 修改下图字典参数 +
+ +3. 自动化 + +
+ + + + +
+ +
+ ## 把数据文件放在 github cache 中
diff --git a/README.md b/README.md index 6fb9829bd30..abe8490f893 100644 --- a/README.md +++ b/README.md @@ -723,6 +723,40 @@ The following steps need to be taken
+## Shortcuts + +
+ +Automate with iOS Shortcuts + +Take the keep app as an example. Close the app after running, and then automatically trigger Actions to update the data. + +1. Get actions id(need to apply token) + +```shell +curl https://api.github.com/repos/yihong0618/running_page/actions/workflows -H "Authorization: token d8xxxxxxxxxx" # change to your config +``` +
get-action-id
+ +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 +
+ +3. Automation + +
+ + + + +
+ +
+ + ## Storing Data Files in GitHub Cache
From a0d6ed5ba22ec7e857bb9ce7ca14af08bab11a10 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Tue, 10 Oct 2023 19:42:53 +0800 Subject: [PATCH 2/2] fix: strava to garmin sync --- run_page/garmin_sync.py | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/run_page/garmin_sync.py b/run_page/garmin_sync.py index 56f66c50725..0ec58e2707e 100755 --- a/run_page/garmin_sync.py +++ b/run_page/garmin_sync.py @@ -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}", } @@ -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}", } @@ -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: @@ -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(