Skip to content

Instantly share code, notes, and snippets.

@desmondmorris
Forked from NorthIsUp/fuel.py
Created December 19, 2012 13:13
Show Gist options
  • Save desmondmorris/4336572 to your computer and use it in GitHub Desktop.
Save desmondmorris/4336572 to your computer and use it in GitHub Desktop.
# blog post explaining all of this coming soon.
import requests
from pprint import pprint
try:
import simplejson as json
except ImportError:
import json
"""
get the auth token and device id by sniffing the nike app syncing
with api.nike.com with charles
to run you will need to install the following:
pip install requests
pip install simplejson
"""
APPLICATION_JSON = 'application/json'
# when to start getting fuel data from
start_date = '011011'
# when to get data through
end_date = '290815'
# how many buckets to get the data in
fidelity = 24 * 60
headers = {
'Accept': APPLICATION_JSON,
'appid': 'fuelband'
}
params = {
'access_token': 'YOUR AUTH TOKEN',
'deviceId': 'YOUR DEVICE ID',
'endDate': end_date,
'fidelity': fidelity,
}
d = {
'protocol': 'https',
'domain': 'api.nike.com',
'version': 'v1.0',
'path': 'me/activities/summary/%s' % start_date,
}
url = '{protocol}://{domain}/{version}/{path}'.format(**d)
print url
print 'I solemnly swear that I am up to no good.'
r = requests.get(
url,
params=params,
headers=headers,
)
# Dump the raw data
f = open('fueldump_raw.json', 'w')
f.write(r.text)
f.close()
# write it out formatted nicely
f = open('fueldump_format.json', 'w')
json.dump(json.loads(r.text), f, indent=2)
f.close()
print 'Mischief managed'
# Uncomment to print the data, it is a lot of data...
# for activity in loaded['daily']:
# print activity['activityIds']
# print [x['fuel'] for x in activity['history']]
# summary = activity['summary']
# print summary['activeTime']
# print summary['calories']
# print summary['distance']
# print summary['startDate']
# print summary['totalFuel']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment