Skip to content

Commit

Permalink
Merge branch 'refs/heads/upstream' into feat-elevation-gain
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-29 committed Aug 19, 2024
2 parents 16b9613 + 6240702 commit 41031ca
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 32 deletions.
43 changes: 40 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
| [yaoper](https://github.com/yaoper) | <https://running.yaoper.cn> | codoon |
| [NoZTurn](https://github.com/NoZTurn) | <https://run.jiangkai.org> | Strava |
| [laqieer](https://github.com/laqieer) | <https://laqieer.github.io/running_page/> | Strava |
| [Guoxin](https://github.com/guoxinl) | <https://running.guoxin.space/> | Strava |
| [Darren](https://github.com/Flavored4179) | <https://run.wdoc.top/> | tcx |
</details>

## 它是怎么工作的
Expand Down Expand Up @@ -134,6 +136,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
## 支持

- **[Strava](#strava)**
- **[New Way To Sync Nike Run Club](#nike-run-club-new)** :NFC同步的新方式
- **[Nike Run Club](#nike-run-club)**
- **[Garmin](#garmin)**
- **[Garmin-cn](#garmin-cn-大陆用户请用这个)**
Expand All @@ -147,7 +150,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
- **[佳明国内同步国际](#Garmin-CN-to-Garmin)**
- **[Tcx+Strava(upload all tcx data to strava)](#tcx_to_strava)**
- **[Tcx+Garmin(upload all tcx data to Garmin)](#tcx_to_garmin)**
- **[Gpx+Strava(upload all tcx data to strava)](#gpx_to_strava)**
- **[Gpx+Strava(upload all gpx data to strava)](#gpx_to_strava)**
- **[Nike+Strava(Using NRC Run, Strava backup data)](#nikestrava)**
- **[Garmin_to_Strava(Using Garmin Run, Strava backup data)](#garmin_to_strava)**
- **[Strava_to_Garmin(Using Strava Run, Garmin backup data)](#strava_to_garmin)**
Expand Down Expand Up @@ -400,13 +403,13 @@ TRANS_GCJ02_TO_WGS84 = True
![image](https://user-images.githubusercontent.com/15976103/102352588-e3af3000-3fe2-11eb-8131-14946b0262eb.png)

```bash
python3(python) run_page/joyrun_sync.py ${your mobile} ${your 验证码}
python3(python) run_page/joyrun_sync.py ${your mobile} ${your 验证码} --athlete ${your own name}
```

示例:

```bash
python3(python) run_page/joyrun_sync.py 13333xxxx xxxx
python3(python) run_page/joyrun_sync.py 13333xxxx xxxx --athlete yihong0618
```

joyrun 导出 gpx 文件
Expand All @@ -433,6 +436,12 @@ python3(python) run_page/joyrun_sync.py 13333xxxx example --with-gpx
python3(python) run_page/joyrun_sync.py 1393xx30xxxx 97e5fe4997d20f9b1007xxxxx --from-uid-sid --with-gpx
```

> 支持配置min_grid_distance,默认为10
```bash
python3(python) run_page/joyrun_sync.py 13333xxxx xxxx --athlete yihong0618 --min_grid_distance 5
```

</details>

### Codoon(咕咚)
Expand Down Expand Up @@ -636,6 +645,34 @@ python3(python) run_page/garmin_sync_cn_global.py ${garmin_cn_secret_string} ${g

</details>

### Nike Run Club New

<details>
<summary>Get your <code>Nike Run Club</code> data</summary>

<br>

> Please note:由于nike run club已经在中国大陆停止运营,所以只能通过vpn的方式进行登录。在开始之前先确认自己是全局的非中国大陆的代理,能够正确的访问`nike.com`而不是`nike.com.cn` 如下图所示.
![nike.com](https://github.com/user-attachments/assets/8ce6ae8f-4bc6-4522-85ec-3e5b7590e96d)
<br>

1. 登录/注册 [NikeRunClub](https://www.nike.com/) 账号
![login](https://github.com/user-attachments/assets/659341fb-4abf-491e-bda7-bfca968921b3)
2. 登录成功后,键盘打开F12->Application->localstorage-> 复制键为`https://www.nike.com`的值中的`access_token`的内容.
![developer_mode](https://github.com/user-attachments/assets/c932318d-a123-4505-8fd8-b46946c25d29)
3. 修改 `nike_sync.py` 文件中的代码,并且把你刚才复制的内容粘贴进去 如下图所示.
![nike_sync.py](https://github.com/user-attachments/assets/6de91725-ed17-4338-96d5-727eb75cee24)
4. 在根目录执行,你应该就可以看到下图中的内容,然后你就可以正常在你的手机版NRC里登录你的账号了:

```bash
python3(python) run_page/nike_sync.py aaaaa
```
![tg_image_166091873](https://github.com/user-attachments/assets/9d4851d6-849a-4bb7-8ffe-5358fa7328b2)

如果你想自动化同步NRC中的运动数据,去 [issue692](https://github.com/yihong0618/running_page/issues/692#issuecomment-2218849713)中查看相关内容.

</details>

### Nike Run Club

Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/
| [Zeonsing](https://github.com/NoonieBao) | <https://run.jogzeal.com/> | Coros |
| [yaoper](https://github.com/yaoper) | <https://running.yaoper.cn> | codoon |
| [laqieer](https://github.com/laqieer) | <https://laqieer.github.io/running_page/> | Strava |
| [Guoxin](https://github.com/guoxinl) | <https://running.guoxin.space/> | Strava |
| [laihj](https://github.com/laihj) | <https://run.laihjx.com/> | 苹果健身 |
</details>

## How it works
Expand All @@ -123,6 +125,7 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/

- **[Garmin](#garmin)**
- **[Garmin-CN](#garmin-cnchina)**
- **[New Way To Sync Nike Run Club](#nike-run-club-new)**
- **[Nike Run Club](#nike-run-club)**
- **[Strava](#strava)**
- **[GPX](#gpx)**
Expand Down Expand Up @@ -435,6 +438,35 @@ python3(python) run_page/garmin_sync_cn_global.py ${garmin_cn_secret_string} ${g

</details>

### Nike Run Club New

<details>
<summary>Get your <code>Nike Run Club</code> data</summary>

<br>

> Please note:Due to the discontinuation of Nike Run Club in mainland China, you can only log in through a VPN. Before starting, please ensure that you are using a global non-mainland China proxy, allowing you to access `nike.com` instead of `nike.com.cn`, as shown in the following image.
![nike.com](https://github.com/user-attachments/assets/8ce6ae8f-4bc6-4522-85ec-3e5b7590e96d)
<br>

1. Sign in/Sign up [NikeRunClub](https://www.nike.com/) account
![login](https://github.com/user-attachments/assets/659341fb-4abf-491e-bda7-bfca968921b3)
2. after successful login,openF12->Application->localstorage-> copy the content of "access_token" from the value of key`https://www.nike.com`.
![developer_mode](https://github.com/user-attachments/assets/c932318d-a123-4505-8fd8-b46946c25d29)
3. modify the code in the "nike_sync.py" file and paste the content you just copied as shown in the following image.
![nike_sync.py](https://github.com/user-attachments/assets/6de91725-ed17-4338-96d5-727eb75cee24)
4. Execute in the root directory , you should be able to see the image below, and then you can log into your account on the mobile as usual:

```bash
python3(python) run_page/nike_sync.py aaaaa
```
![tg_image_166091873](https://github.com/user-attachments/assets/9d4851d6-849a-4bb7-8ffe-5358fa7328b2)

if you want to automate the submission of NRC data, you can refer to [issue692](https://github.com/yihong0618/running_page/issues/692#issuecomment-2218849713).

</details>

### Nike Run Club

<details>
Expand Down
2 changes: 1 addition & 1 deletion assets/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/github_2024.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/year_2024.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion run_page/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def sync_from_data_dir(self, data_dir, file_suffix="gpx"):
synced_files = []

for t in tracks:
created = update_or_create_activity(self.session, t.to_namedtuple())
created = update_or_create_activity(
self.session, t.to_namedtuple(run_from=file_suffix)
)
if created:
sys.stdout.write("+")
else:
Expand Down
17 changes: 15 additions & 2 deletions run_page/gpxtrackposter/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self):
self.run_id = 0
self.start_latlng = []
self.type = "Run"
self.device = ""

def load_gpx(self, file_name):
"""
Expand Down Expand Up @@ -286,6 +287,14 @@ def _load_fit_data(self, fit: dict):
self.start_time, self.end_time, None
)

# The FIT file created by Garmin
if "file_id_mesgs" in fit:
device_message = fit["file_id_mesgs"][0]
if "manufacturer" in device_message:
self.device = device_message["manufacturer"]
if "garmin_product" in device_message:
self.device += " " + device_message["garmin_product"]

def append(self, other):
"""Append other track to self."""
self.end_time = other.end_time
Expand Down Expand Up @@ -329,10 +338,14 @@ def _get_moving_data(gpx):
),
}

def to_namedtuple(self):
def to_namedtuple(self, run_from="gpx"):
d = {
"id": self.run_id,
"name": "run from gpx", # maybe change later
"name": (
f"run from {run_from} by {self.device}"
if self.device
else f"run from {run_from}"
), # maybe change later
"type": "Run", # Run for now only support run for now maybe change later
"start_date": self.start_time.strftime("%Y-%m-%d %H:%M:%S"),
"end": self.end_time.strftime("%Y-%m-%d %H:%M:%S"),
Expand Down
88 changes: 88 additions & 0 deletions run_page/joyrun_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import argparse
import json
import os
import subprocess
import sys
import time
from collections import namedtuple
from datetime import datetime, timedelta
Expand Down Expand Up @@ -374,12 +376,95 @@ def get_all_joyrun_tracks(self, old_tracks_ids, with_gpx=False):
return tracks


def _generate_svg_profile(athlete, min_grid_distance):
# To generate svg for 'Total' in the left-up map
if not athlete:
# Skip to avoid override
print("Skipping gen_svg. Fill your name with --athlete if you don't want skip")
return
print(
f"Running scripts for [Make svg GitHub profile] with athlete={athlete} min_grid_distance={min_grid_distance}"
)
cmd_args_list = [
[
sys.executable,
"run_page/gen_svg.py",
"--from-db",
"--title",
f"{athlete} Running",
"--type",
"github",
"--athlete",
athlete,
"--special-distance",
"10",
"--special-distance2",
"20",
"--special-color",
"yellow",
"--special-color2",
"red",
"--output",
"assets/github.svg",
"--use-localtime",
"--min-distance",
"0.5",
],
[
sys.executable,
"run_page/gen_svg.py",
"--from-db",
"--title",
f"Over {min_grid_distance} Running",
"--type",
"grid",
"--athlete",
athlete,
"--special-distance",
"20",
"--special-distance2",
"40",
"--special-color",
"yellow",
"--special-color2",
"red",
"--output",
"assets/grid.svg",
"--use-localtime",
"--min-distance",
str(min_grid_distance),
],
[
sys.executable,
"run_page/gen_svg.py",
"--from-db",
"--type",
"circular",
"--use-localtime",
],
]
for cmd_args in cmd_args_list:
subprocess.run(cmd_args, check=True)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("phone_number_or_uid", help="joyrun phone number or uid")
parser.add_argument(
"identifying_code_or_sid", help="joyrun identifying_code from sms or sid"
)
parser.add_argument(
"--athlete",
dest="athlete",
help="athlete, keep same with {env.ATHLETE}",
)
parser.add_argument(
"--min_grid_distance",
dest="min_grid_distance",
help="min_grid_distance, keep same with {env.MIN_GRID_DISTANCE}",
type=int,
default=10,
)
parser.add_argument(
"--with-gpx",
dest="with_gpx",
Expand Down Expand Up @@ -412,3 +497,6 @@ def get_all_joyrun_tracks(self, old_tracks_ids, with_gpx=False):
activities_list = generator.load()
with open(JSON_FILE, "w") as f:
json.dump(activities_list, f)

print("Data export to DB done")
_generate_svg_profile(options.athlete, options.min_grid_distance)
11 changes: 4 additions & 7 deletions run_page/keep_to_strava_sync.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import argparse
import json
import os
from sre_constants import SUCCESS
import time
from collections import namedtuple
import requests
from config import GPX_FOLDER
from Crypto.Cipher import AES
from config import OUTPUT_DIR
from stravalib.exc import ActivityUploadFailed, RateLimitTimeout
from utils import make_strava_client, upload_file_to_strava
from keep_sync import KEEP_DATA_TYPE_API, get_all_keep_tracks
from keep_sync import KEEP_SPORT_TYPES, get_all_keep_tracks
from strava_sync import run_strava_sync

"""
Expand Down Expand Up @@ -72,10 +69,10 @@ def run_keep_sync(email, password, keep_sports_data_api, with_download_gpx=False
)

options = parser.parse_args()
for api in options.sync_types:
for _tpye in options.sync_types:
assert (
api in KEEP_DATA_TYPE_API
), f"{api} are not supported type, please make sure that the type entered in the {KEEP_DATA_TYPE_API}"
_tpye in KEEP_SPORT_TYPES
), f"{_tpye} are not supported type, please make sure that the type entered in the {KEEP_SPORT_TYPES}"
new_tracks = run_keep_sync(
options.phone_number, options.password, options.sync_types, True
)
Expand Down
29 changes: 15 additions & 14 deletions run_page/nike_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ class Nike:
def __init__(self, refresh_token):
self.client = httpx.Client()

response = self.client.post(
TOKEN_REFRESH_URL,
headers=NIKE_HEADERS,
json={
"refresh_token": refresh_token,
"client_id": b64decode(NIKE_CLIENT_ID).decode(),
"grant_type": "refresh_token",
"ux_id": b64decode(NIKE_UX_ID).decode(),
},
timeout=60,
)
response.raise_for_status()

access_token = response.json()["access_token"]
# response = self.client.post(
# TOKEN_REFRESH_URL,
# headers=NIKE_HEADERS,
# json={
# "refresh_token": refresh_token,
# "client_id": b64decode(NIKE_CLIENT_ID).decode(),
# "grant_type": "refresh_token",
# "ux_id": b64decode(NIKE_UX_ID).decode(),
# },
# timeout=60,
# )
# response.raise_for_status()
#
# access_token = response.json()["access_token"]
access_token = "The content of 'access_token' that you just copied."
self.client.headers.update({"Authorization": f"Bearer {access_token}"})

def get_activities_since_timestamp(self, timestamp):
Expand Down
2 changes: 1 addition & 1 deletion src/static/activities.json

Large diffs are not rendered by default.

0 comments on commit 41031ca

Please sign in to comment.