starting to work on nkstuff.get_workout
This commit is contained in:
@@ -116,7 +116,6 @@ def do_refresh_token(refreshtoken):
|
||||
url = oauth_data['base_url']
|
||||
|
||||
response = requests.post(url,data=post_data,auth=HTTPBasicAuth(oauth_data['client_id'],oauth_data['client_secret']))
|
||||
print(response.status_code)
|
||||
|
||||
if response.status_code != 200:
|
||||
return [0,0,0]
|
||||
@@ -150,7 +149,7 @@ def make_authorization_url(request):
|
||||
|
||||
def get_nk_workout_list(user,fake=False):
|
||||
r = Rower.objects.get(user=user)
|
||||
print(r.nktoken,r.nktokenexpirydate)
|
||||
|
||||
if (r.nktoken == '') or (r.nktoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401,s)
|
||||
@@ -181,24 +180,54 @@ def get_nk_workout_list(user,fake=False):
|
||||
|
||||
return s
|
||||
|
||||
def get_nk_workout_strokes(user,nkid):
|
||||
r = Rower.objects.get(user=user)
|
||||
|
||||
if (r.nktoken == '') or (r.nktoken is None):
|
||||
return custom_exception_handler(401,s)
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
elif (timezone.now()>r.tokenexpirydate):
|
||||
s = "Token expired. Needs to refresh."
|
||||
return custom_exception_handler(401,s)
|
||||
else:
|
||||
# ready to fetch. Hurray
|
||||
authorizationstring = str('Bearer ' + r.nktoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json'}
|
||||
url = "https://log.concept2.com/api/users/me/results/"+str(nkid)+"/strokes"
|
||||
s = requests.get(url,headers=headers)
|
||||
|
||||
return s
|
||||
#
|
||||
#def get_workout(user,nkid):
|
||||
def getdict(x):
|
||||
try:
|
||||
return x[0]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return {}
|
||||
|
||||
def get_workout(user,nkid):
|
||||
print('aap')
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.nktoken == '') or (r.nktoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401,s) ,0
|
||||
elif (timezone.now()>r.nktokenexpirydate):
|
||||
s = "Token expired. Needs to refresh."
|
||||
return custom_exception_handler(401,s),0
|
||||
|
||||
params = {
|
||||
'sessionIds': nkid,
|
||||
}
|
||||
|
||||
authorizationstring = str('Bearer ' + r.nktoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
|
||||
|
||||
# get strokes
|
||||
url = NK_API_LOCATION+"api/v1/sessions/strokes"
|
||||
response = requests.get(url,headers=headers,params=params)
|
||||
if response != 200:
|
||||
# error handling
|
||||
pass
|
||||
|
||||
data = response.json()[str(nkid)]
|
||||
|
||||
df = pd.DataFrame.from_dict(data)
|
||||
ol = df['oarlockStrokes']
|
||||
ol = ol.apply(lambda x:getdict(x))
|
||||
df2 = pd.DataFrame.from_records(ol.values)
|
||||
df2 = df2.rename(colunms={"timestamp":"ts"})
|
||||
df = pd.concat([df,df2],axis=1)
|
||||
|
||||
# get workout data
|
||||
|
||||
return 0,0
|
||||
|
||||
Reference in New Issue
Block a user