gets strava owner id thru api
This commit is contained in:
@@ -71,6 +71,8 @@ def get_token(code):
|
||||
return imports_get_token(code, oauth_data)
|
||||
|
||||
def strava_open(user):
|
||||
if user.rower.strava_owner_id == 0:
|
||||
strava_owner_id = set_strava_athlete_id(user)
|
||||
return imports_open(user, oauth_data)
|
||||
|
||||
def do_refresh_token(refreshtoken):
|
||||
@@ -95,6 +97,29 @@ def rower_strava_token_refresh(user):
|
||||
def make_authorization_url(request):
|
||||
return imports_make_authorization_url(oauth_data)
|
||||
|
||||
def set_strava_athlete_id(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.stravatoken == '') or (r.stravatoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401,s)
|
||||
elif (r.stravatokenexpirydate is None or timezone.now()+timedelta(seconds=3599)>r.stravatokenexpirydate):
|
||||
s = "Token expired. Needs to refresh."
|
||||
return custom_exception_handler(401,s)
|
||||
else:
|
||||
authorizationstring = str('Bearer ' + r.stravatoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json'}
|
||||
url = "https://www.strava.com/api/v3/athlete"
|
||||
|
||||
response = requests.get(url,headers=headers,params={})
|
||||
|
||||
r.strava_owner_id = response.json()['id']
|
||||
r.save()
|
||||
|
||||
return response.json()['id']
|
||||
|
||||
|
||||
# Get list of workouts available on Strava
|
||||
def get_strava_workout_list(user,limit_n=0):
|
||||
r = Rower.objects.get(user=user)
|
||||
|
||||
Reference in New Issue
Block a user