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 committed Oct 24, 2023
2 parents ff62d0d + a7b2e68 commit 7349d81
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
9 changes: 8 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
| [jianchengwang](https://github.com/jianchengwang) | <https://jianchengwang.github.io/running_page> | Suunto |
| [fxbin](https://github.com/fxbin) | <https://fxbin.github.io/sport-records/> | Keep |
| [shensl4499](https://github.com/shensl4499) | <https://waner.run> | codoon |
| [haowei93](https://github.com/haowei93) | <https://haowei93.github.io/> | gpx |
| [haowei93](https://github.com/haowei93) | <https://running-fun.eu.org> | gpx |
| [stevenash0822](https://github.com/stevenash0822) | <https://run.imangry.xyz/> | Strava |
| [Vint](https://github.com/VintLin) | <https://vinton.store/Running/> | Keep |
| [Muyids](https://github.com/muyids) | <https://muyids.github.io/running> | Garmin-cn |
Expand All @@ -85,6 +85,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
| [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 |
| [s1smart](https://github.com/s1smart) | <https://s1smart.github.io/running_page/> | Strava |

</details>

Expand Down Expand Up @@ -575,6 +576,12 @@ python3(python) run_page/nike_sync.py eyJhbGciThiMTItNGIw******
https://www.strava.com/oauth/authorize?client_id=${your_id}&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=read_all,profile:read_all,activity:read_all,profile:write,activity:write
```

Example:

```
https://www.strava.com/oauth/authorize?client_id=115321&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=read_all,profile:read_all,activity:read_all,profile:write,activity:write
```

![get_all_permissions](https://raw.githubusercontent.com/shaonianche/gallery/master/running_page/get_all_permissions.png)

5. 提取授权后返回链接中的 code 值
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/
| [jianchengwang](https://github.com/jianchengwang) | <https://jianchengwang.github.io/running_page> | Suunto |
| [fxbin](https://github.com/fxbin) | <https://fxbin.github.io/sport-records/> | Keep |
| [shensl4499](https://github.com/shensl4499) | <https://waner.run> | codoon |
| [haowei93](https://github.com/haowei93) | <https://haowei93.github.io/> | gpx |
| [haowei93](https://github.com/haowei93) | <https://running-fun.eu.org> | gpx |
| [stevenash0822](https://github.com/stevenash0822) | <https://run.imangry.xyz/> | Strava |
| [Vint](https://github.com/VintLin) | <https://vinton.store/Running/> | Keep |
| [Muyids](https://github.com/muyids) | <https://muyids.github.io/running> | Garmin-cn |
Expand All @@ -83,6 +83,7 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/
| [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 |
| [s1smart](https://github.com/s1smart) | <https://s1smart.github.io/running_page/> | Strava |

</details>

Expand Down Expand Up @@ -412,6 +413,12 @@ Created successfully:
https://www.strava.com/oauth/authorize?client_id=${your_id}&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=read_all,profile:read_all,activity:read_all,profile:write,activity:write
```

Example:

```
https://www.strava.com/oauth/authorize?client_id=115321&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=read_all,profile:read_all,activity:read_all,profile:write,activity:write
```

![get_all_permissions](https://raw.githubusercontent.com/shaonianche/gallery/master/running_page/get_all_permissions.png)

5. Get the `code` value in the link
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tzlocal
fit-tool
haversine==2.8.0
garth
pycryptodome

62 changes: 31 additions & 31 deletions run_page/keep_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import polyline
import requests
from config import GPX_FOLDER, JSON_FILE, SQL_FILE, run_map, start_point
from Crypto.Cipher import AES
from generator import Generator
from utils import adjust_time

Expand All @@ -21,16 +22,17 @@
RUN_DATA_API = "https://api.gotokeep.com/pd/v3/stats/detail?dateUnit=all&type=running&lastDate={last_date}"
RUN_LOG_API = "https://api.gotokeep.com/pd/v3/runninglog/{run_id}"

# If your points need trans from gcj02 to wgs84 coordinate which use by Mappbox

# If your points need trans from gcj02 to wgs84 coordinate which use by Mapbox
TRANS_GCJ02_TO_WGS84 = True


def login(session, mobile, passowrd):
def login(session, mobile, password):
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0",
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
}
data = {"mobile": mobile, "password": passowrd}
data = {"mobile": mobile, "password": password}
r = session.post(LOGIN_API, headers=headers, data=data)
if r.ok:
token = r.json()["data"]["token"]
Expand Down Expand Up @@ -64,8 +66,14 @@ def get_single_run_data(session, headers, run_id):
return r.json()


def decode_runmap_data(text):
run_points_data = zlib.decompress(base64.b64decode(text), 16 + zlib.MAX_WBITS)
def decode_runmap_data(text, is_geo=False):
_bytes = base64.b64decode(text)
key = "NTZmZTU5OzgyZzpkODczYw=="
iv = "MjM0Njg5MjQzMjkyMDMwMA=="
if is_geo:
cipher = AES.new(base64.b64decode(key), AES.MODE_CBC, base64.b64decode(iv))
_bytes = cipher.decrypt(_bytes)
run_points_data = zlib.decompress(_bytes, 16 + zlib.MAX_WBITS)
run_points_data = json.loads(run_points_data)
return run_points_data

Expand All @@ -80,33 +88,25 @@ def parse_raw_data_to_nametuple(
keep_id = run_data["id"].split("_")[1]

start_time = run_data["startTime"]
if run_data.get("vendor", {}).get("source", "") == "Keep" and run_data.get(
"rawDataURL"
):
raw_data_url = run_data.get("rawDataURL")
r = session.get(raw_data_url)
if r.ok:
# string strart with `H4sIAAAAAAAA` --> decode and unzip
run_points_data = decode_runmap_data(r.text)
run_points_data_gpx = run_points_data
if TRANS_GCJ02_TO_WGS84:
run_points_data = [
list(eviltransform.gcj2wgs(p["latitude"], p["longitude"]))
for p in run_points_data
]
for i, p in enumerate(run_points_data_gpx):
p["latitude"] = run_points_data[i][0]
p["longitude"] = run_points_data[i][1]
else:
run_points_data = [
[p["latitude"], p["longitude"]] for p in run_points_data
]
if with_download_gpx:
if str(keep_id) not in old_gpx_ids:
gpx_data = parse_points_to_gpx(run_points_data_gpx, start_time)
download_keep_gpx(gpx_data, str(keep_id))
if run_data["geoPoints"]:
run_points_data = decode_runmap_data(run_data["geoPoints"], True)
run_points_data_gpx = run_points_data
if TRANS_GCJ02_TO_WGS84:
run_points_data = [
list(eviltransform.gcj2wgs(p["latitude"], p["longitude"]))
for p in run_points_data
]
for i, p in enumerate(run_points_data_gpx):
p["latitude"] = run_points_data[i][0]
p["longitude"] = run_points_data[i][1]
else:
print(f"ID {keep_id} retrieved gpx data failed")
run_points_data = [[p["latitude"], p["longitude"]] for p in run_points_data]
if with_download_gpx:
if str(keep_id) not in old_gpx_ids:
gpx_data = parse_points_to_gpx(run_points_data_gpx, start_time)
download_keep_gpx(gpx_data, str(keep_id))
else:
print(f"ID {keep_id} no gps data")
heart_rate = None
if run_data["heartRate"]:
heart_rate = run_data["heartRate"].get("averageHeartRate", None)
Expand Down
1 change: 0 additions & 1 deletion run_page/nike_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
run_map,
)
from generator import Generator

from utils import adjust_time, make_activities_file

# logging.basicConfig(level=logging.INFO)
Expand Down

0 comments on commit 7349d81

Please sign in to comment.