Пример #1
0
class APIManager:
	def __init__ (self):
		self.api = Jawbone ('', '', '', '')

	def add_param_if_not_none (self, params, key, value):
		if value is not None:
			params[key] = value

	#
	# https://jawbone.com/up/developer/endpoints/moves
	#
	def get_moves (self, token, params):
		valid_params = ['date', 'page_token', 'start_time', 'end_time', 'updated_after']

		for key in params.keys():
			if key not in valid_params:
				raise ValueError ("Invalid key '%s' in function '%s'" % (key, utilities.current_function_name()))

		return self.api.api_call (token.TokenAccessToken, "nudge/api/v.1.1/users/@me/moves", **params)

	def get_sleeps (self, token, params):
		valid_params = ['date', 'page_token', 'start_time', 'end_time', 'updated_after']

		for key in params.keys():
			if key not in valid_params:
				raise ValueError ("Invalid key '%s' in function '%s'" % (key, utilities.current_function_name()))

		return self.api.api_call (token.TokenAccessToken, "nudge/api/v.1.1/users/@me/sleeps", **params)

	def get_sleep_phases (self, token, xid):
		url = "nudge/api/v.1.1/sleeps/{0}/ticks".format (xid)

		return self.api.api_call (token.TokenAccessToken, url)
Пример #2
0
	def __init__ (self):
		self.api = Jawbone ('', '', '', '')
Пример #3
0
from jawbone import Jawbone


client_id = r''
client_secret = r''
redirect_uri = ''

jb = Jawbone(client_id, client_secret, redirect_uri, scope='basic_read extended_read sleep_read move_read')

#if you don't have a token yet, then 
#print jb.auth()
#produces a url, put that url in a browser, you'll get back a page with a code in the url
#mytoken = jb.access_token(code)
#access = mytoken['access_token']

access = u''

#gets first 10 results for these. upgrade to get n sometime
endpoint = 'nudge/api/v.1.1/users/@me/sleeps'
response = jb.api_call(access, endpoint)

sleepjson = response['data']

flat = []
for item in sleepjson['items']:
	flat.append((str(item['details']['asleep_time']), str(item['details']['light']), str(item['details']['sound'])))

sleepfile = "sleep.csv"
target = open(sleepfile, 'w')

for line in flat:
Пример #4
0
from jawbone import Jawbone
import csv
import datetime
import urllib


code = 'aV1SI82xvTp7yNo9mcqXNzAMdEzLI7j65MDz9woxiPz7xAtMk3eVufj10-ItJz4R9WnvKI-GaClbU4JadEd7yCHvFlpwU6ifgf1sDnoQ8zQXdB24evV0_J9g7lSkKu4wpmp8xnxzsxVNWa81PUm-HX1RJ4nRH1zRl5cyeb8zhWTk8lNHm2EhXTlQUbAogm-8'

jb = Jawbone()

url = jb.doAuth()
print(url)

access_token = jb.getAccessToken(code)
print(access_token)

#me = jb.api_call(access_token, '/nudge/api/users/@me')
#print(me)

#xid = jb.getUserId(access_token)
#print(xid)

moves = jb.doApiCall(access_token, '/nudge/api/users/@me/moves')

move_items = moves['data']['items']
move_counts = moves['data']['size']

x = []

print(move_counts)
for move in move_items: 
Пример #5
0
from jawbone import Jawbone
import webbrowser

jb = Jawbone('nEXyCKO3F3s',
             'c9a66fc619ccb0e7c2c4e90e59200dfba8aea5de',
             'http://localhost/login/jawbone',
             scope='basic_read extended_read')

redirect = jb.auth()

response = jb.api_call(
    'r5ZHAAV8pCXUBg2Qya-xrn74bRKrSrIWj29SxzFeRjN0HCKkcBV4krGIYeF7UShXRPaV1mvF5JRRAnYEZaPxlCzIBmUT',
    'nudge/api/v.1.0/sleep')

token = access_token(
    'jF_LbmL3sgAtppKeiXW_-M_1H33wGhYwvLzEKq4NpEuSc5-fiPxYrjQ7b97G101kASfWbIWY51xp7CT9C2hu5vXgJbBeGENBqbKHdHLQYmK3BFnpMtk_v_1iHbrzUzvK8aEpsIodBknNWzhLq6VsNHIg8qpbXhP6-Bq-_TO0iJnk8lNHm2EhXXMmcJ9fyPcu'
)
print token