c2, strava done, almost done st
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# All the functionality to connect to SportTracks
|
||||
|
||||
from rowers.imports import *
|
||||
|
||||
import re
|
||||
from rowsandall_app.settings import (
|
||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
||||
@@ -54,7 +54,7 @@ def do_refresh_token(refreshtoken):
|
||||
except (TypeError,ValueError):
|
||||
expires_in = 0
|
||||
|
||||
|
||||
|
||||
return [thetoken,expires_in,refresh_token]
|
||||
|
||||
# Exchange ST access code for long-lived ST access token
|
||||
@@ -74,7 +74,8 @@ def get_token(code):
|
||||
|
||||
response = requests.post(url,
|
||||
data=json.dumps(post_data),
|
||||
headers=headers)
|
||||
headers=headers)
|
||||
|
||||
if response.status_code == 200 or response.status_code == 201:
|
||||
token_json = response.json()
|
||||
thetoken = token_json['access_token']
|
||||
@@ -90,7 +91,6 @@ def get_token(code):
|
||||
else:
|
||||
return [0,0,0]
|
||||
|
||||
|
||||
return [thetoken,expires_in,refresh_token]
|
||||
|
||||
# Make authorization URL including random string
|
||||
@@ -127,6 +127,7 @@ def rower_sporttracks_token_refresh(user):
|
||||
r.sporttracksrefreshtoken = refresh_token
|
||||
|
||||
r.save()
|
||||
|
||||
return r.sporttrackstoken
|
||||
|
||||
# Get list of workouts available on SportTracks
|
||||
@@ -201,9 +202,9 @@ def createsporttracksworkoutdata(w):
|
||||
d[0] = d[1]
|
||||
t = t.astype(int)
|
||||
d = d.astype(int)
|
||||
spm = row.df[' Cadence (stokes/min)'].astype(int)
|
||||
spm = row.df[' Cadence (stokes/min)'].astype(int).values
|
||||
spm[0] = spm[1]
|
||||
hr = row.df[' HRCur (bpm)'].astype(int)
|
||||
hr = row.df[' HRCur (bpm)'].astype(int).values
|
||||
|
||||
haslatlon=1
|
||||
|
||||
@@ -218,7 +219,7 @@ def createsporttracksworkoutdata(w):
|
||||
|
||||
haspower = 1
|
||||
try:
|
||||
power = row.df[' Power (watts)'].values
|
||||
power = row.df[' Power (watts)'].astype(int).values
|
||||
except KeyError:
|
||||
haspower = 0
|
||||
|
||||
@@ -289,9 +290,12 @@ def createsporttracksworkoutdata(w):
|
||||
# Obtain SportTracks Workout ID from the response returned on successful
|
||||
# upload
|
||||
def getidfromresponse(response):
|
||||
t = json.loads(response.text)
|
||||
t = response.json()
|
||||
uri = t['uris'][0]
|
||||
id = uri[len(uri)-13:len(uri)-5]
|
||||
regex = '.*?sporttracks\.mobi\/api\/v2\/fitnessActivity/(\d+)$'
|
||||
m = re.compile(regex).match(uri).group(1)
|
||||
|
||||
id = int(m)
|
||||
|
||||
return int(id)
|
||||
|
||||
@@ -310,7 +314,7 @@ def workout_sporttracks_upload(user,w):
|
||||
message = "Data error"
|
||||
stid = 0
|
||||
return message,stid
|
||||
|
||||
|
||||
authorizationstring = str('Bearer ' + thetoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
@@ -327,7 +331,7 @@ def workout_sporttracks_upload(user,w):
|
||||
w.save()
|
||||
return message, stid
|
||||
elif (response.status_code == 201 or response.status_code==200):
|
||||
s= json.loads(response.text)
|
||||
s= response.json()
|
||||
stid = getidfromresponse(response)
|
||||
w.uploadedtosporttracks = stid
|
||||
w.save()
|
||||
|
||||
Reference in New Issue
Block a user