Created
November 4, 2013 13:56
-
-
Save icebeat/7302813 to your computer and use it in GitHub Desktop.
Export your Nike plus activities and save the world.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests | |
# 0. https://gist.github.com/leah/5655437 (The base) | |
# 1. easy_install requests (install dependency) | |
# 2. python nikeplus.py | |
# 3. Enjoy! | |
TOKEN = "YOUR TOKEN" # http://developer.nike.com | |
PATH2SAVE = "/" | |
API_URL = "https://api.nike.com" | |
HEADERS = { "appid":"%appid%", "Accept": "application/json" } | |
activities_url = "/me/sport/activities?access_token=%s" % TOKEN | |
while activities_url: | |
request = requests.get( "%s%s" % (API_URL, activities_url), headers=HEADERS) | |
response = request.json() | |
if response.get("data"): | |
for activity in response.get("data"): | |
activity_id = activity.get("activityId") | |
start_time = activity.get("startTime") | |
# Output | |
print "ID: %s DATE: %s" % (activity_id, start_time) | |
activity_info = requests.get("%s/me/sport/activities/%s?access_token=%s" % (API_URL, activity_id, TOKEN), headers=HEADERS).json() | |
activity_gps = requests.get("%s/me/sport/activities/%s/gps?access_token=%s" % (API_URL, activity_id, TOKEN), headers=HEADERS).json() | |
# Join details | |
activity_info["gps"] = activity_gps | |
# Save activity | |
activity_file = open(PATH2SAVE + start_time + ".json", "w") | |
activity_file.write(json.dumps(activity_info).encode("utf-8")) | |
activity_file.close() | |
# pagination | |
activities_url = False | |
if response.get("paging") and response.get("paging").get("next"): | |
activities_url = response.get("paging").get("next") | |
else: | |
# exit while | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment