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 Nov 23, 2023
2 parents e7101be + 9727d59 commit e418044
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
11 changes: 8 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,15 @@ python3(python) run_page/garmin_sync.py xxxxxxxxxx --is-cn --only-run
获取 Nike 的 refresh_token

1. 登录 [Nike](https://www.nike.com) 官网
2. In Developer -> Application-> Storage -> https:unite.nike.com 中找到 refresh_token
**全部需要在大陆以外的全局 ip 下进行**

![image](https://user-images.githubusercontent.com/15976103/94448123-23812b00-01dd-11eb-8143-4b0839c31d90.png) 3. 在项目根目录下执行:
![example img](https://user-images.githubusercontent.com/67903793/282300381-4e7437d0-65a9-4eed-93d1-2b70e360215f.png)

1. 在这里登陆[website](https://unite.nike.com/s3/unite/mobile.html?androidSDKVersion=3.1.0&corsoverride=https%3A%2F%2Funite.nike.com&uxid=com.nike.sport.running.droid.3.8&backendEnvironment=identity&view=login&clientId=VhAeafEGJ6G8e9DxRUz8iE50CZ9MiJMG), 打开 F12 在浏览器抓 login -> XHR -> get the `refresh_token` from login api

2. 复制 `refresh_token` 之后可以添加在GitHub Secrets 中,也可以直接在命令行中使用

> Chrome 浏览器:按下 F12 打开浏览器开发者工具,点击 Application 选项卡,来到左侧的 Storage 面板,点击展开 Local storage,点击下方的 https://unite.nike.com。接着点击右侧的 com.nike.commerce.nikedotcom.web.credential Key,下方会分行显示我们选中的对象,可以看到 refresh_token ,复制 refresh_token 右侧的值。Safari 浏览器:在 Safari 打开 Nike 的网页后,右击页面,选择「检查元素」,打开浏览器开发者工具。点击「来源」选项卡,在左侧找到 XHR 文件夹,点击展开,在下方找到 login 文件并单击,在右侧同样可以看到 refresh_token ,复制 refresh_token 右侧的值。
```bash
python3(python) run_page/nike_sync.py ${nike refresh_token}
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,13 @@ python3(python) run_page/garmin_sync.py xxxxxxxxxxxxxx(secret_string) --is-cn -
Get Nike's `refresh_token`

1. Login [Nike](https://www.nike.com) website
2. In Develop -> Application-> Storage -> https:unite.nike.com look for `refresh_token`
**ALL need to do outside GFW**

<br>
![example img](https://user-images.githubusercontent.com/67903793/282300381-4e7437d0-65a9-4eed-93d1-2b70e360215f.png)

1. Login from this [website](https://unite.nike.com/s3/unite/mobile.html?androidSDKVersion=3.1.0&corsoverride=https%3A%2F%2Funite.nike.com&uxid=com.nike.sport.running.droid.3.8&backendEnvironment=identity&view=login&clientId=VhAeafEGJ6G8e9DxRUz8iE50CZ9MiJMG), open F12 -> XHR -> get the `refresh_token` from login api.

![image](https://user-images.githubusercontent.com/15976103/94448123-23812b00-01dd-11eb-8143-4b0839c31d90.png)
2. copy this `refresh_token` and use it in GitHub Secrets or in command line

3. Execute in the root directory:

Expand Down
7 changes: 3 additions & 4 deletions run_page/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
JSON_FILE = os.path.join(parent, "src", "static", "activities.json")
SYNCED_FILE = os.path.join(parent, "imported.json")

# TODO: Move into nike_sync
BASE_URL = "https://api.nike.com/sport/v3/me"
TOKEN_REFRESH_URL = "https://unite.nike.com/tokenRefresh"
NIKE_CLIENT_ID = "HlHa2Cje3ctlaOqnxvgZXNaAs7T9nAuH"
# TODO: Move into nike_sync NRC THINGS


BASE_TIMEZONE = "Asia/Shanghai"


Expand Down
18 changes: 14 additions & 4 deletions run_page/nike_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
from base64 import b64decode
import json
import logging
import os.path
Expand All @@ -11,13 +12,10 @@
import httpx
from config import (
BASE_TIMEZONE,
BASE_URL,
GPX_FOLDER,
JSON_FILE,
NIKE_CLIENT_ID,
OUTPUT_DIR,
SQL_FILE,
TOKEN_REFRESH_URL,
run_map,
)
from generator import Generator
Expand All @@ -26,17 +24,29 @@
# logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("nike_sync")

BASE_URL = "https://api.nike.com/sport/v3/me"
TOKEN_REFRESH_URL = "https://api.nike.com/idn/shim/oauth/2.0/token"
NIKE_CLIENT_ID = "VmhBZWFmRUdKNkc4ZTlEeFJVejhpRTUwQ1o5TWlKTUc="
NIKE_UX_ID = "Y29tLm5pa2Uuc3BvcnQucnVubmluZy5pb3MuNS4xNQ=="
NIKE_HEADERS = {
"Host": "api.nike.com",
"Accept": "application/json",
"Content-Type": "application/json",
}


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": NIKE_CLIENT_ID,
"client_id": b64decode(NIKE_CLIENT_ID).decode(),
"grant_type": "refresh_token",
"ux_id": b64decode(NIKE_UX_ID).decode(),
},
timeout=60,
)
Expand Down
2 changes: 1 addition & 1 deletion run_page/strava_to_garmin_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def upload_to_activities(
return files_list

# strava rate limit
for i in strava_activities[: len(strava_activities)]:
for i in sorted(strava_activities, key=lambda i: int(i.id)):
try:
data = strava_web_client.get_activity_data(i.id, fmt=format)
files_list.append(data)
Expand Down

0 comments on commit e418044

Please sign in to comment.