Created
September 24, 2013 03:25
-
-
Save abegong/6679997 to your computer and use it in GitHub Desktop.
Retrieve the last 10 days of UP data from the jawbone nudge API
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 requests | |
import json | |
import pandas | |
import pylab as plt | |
import auth | |
# Get auth token | |
r = requests.post("https://jawbone.com/user/signin/login", { | |
'pwd': auth.pwd, | |
'email': auth.email, | |
'service': 'nudge' | |
}) | |
token = json.loads(r.text)['token'] | |
# Get list of recent moves | |
data = requests.get("https://jawbone.com/nudge/api/users/@me/moves", headers={'x-nudge-token': token}) | |
j = data.json() | |
# Store as json blob | |
file("data/moves.json", 'w').write(json.dumps(j, indent=2)) | |
# Get all the moves object snapshots | |
M = [] | |
for i,item in enumerate(j["data"]["items"]): | |
move_xid = item["xid"] | |
req = requests.get("https://jawbone.com/nudge/api/moves/" + move_xid + "/snapshot", headers={'x-nudge-token': token}) | |
move_data = json.loads(req.text) | |
M.append(move_data) | |
# Store to jsonline file | |
file("data/snapshots.jl", 'w').write("\n".join([json.dumps(m) for m in M])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment