able to retrieve session list from rojabo
This commit is contained in:
@@ -845,16 +845,16 @@ def get_c2_workout_list(user, page=1):
|
||||
s = "Token expired. Needs to refresh."
|
||||
|
||||
return custom_exception_handler(401, s)
|
||||
else:
|
||||
# ready to fetch. Hurray
|
||||
authorizationstring = str('Bearer ' + r.c2token)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json'}
|
||||
url = "https://log.concept2.com/api/users/me/results"
|
||||
url += "?page={page}".format(page=page)
|
||||
|
||||
s = requests.get(url, headers=headers)
|
||||
# ready to fetch. Hurray
|
||||
authorizationstring = str('Bearer ' + r.c2token)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json'}
|
||||
url = "https://log.concept2.com/api/users/me/results"
|
||||
url += "?page={page}".format(page=page)
|
||||
|
||||
s = requests.get(url, headers=headers)
|
||||
|
||||
return s
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from rowers.models import Rower, Workout, TombStone
|
||||
from rowers import utils
|
||||
import datetime
|
||||
|
||||
from rowers.imports import *
|
||||
from rowsandall_app.settings import (
|
||||
@@ -86,7 +87,7 @@ def rojabo_open(user):
|
||||
if (r.rojabo_token == '') or (r.rojabo_token is None):
|
||||
raise NoTokenError("User has no token")
|
||||
else:
|
||||
if (timezone.now() > r.tokenexpirydate):
|
||||
if (timezone.now() > r.rojabo_tokenexpirydate):
|
||||
res = rower_rojabo_token_refresh(user)
|
||||
if res is None: # pragma: no cover
|
||||
raise NoTokenError("User has no token")
|
||||
@@ -106,7 +107,7 @@ def rower_rojabo_token_refresh(user):
|
||||
access_token = res[0]
|
||||
expires_in = res[1]
|
||||
refresh_token = res[2]
|
||||
expirydatetime = timezone.now()+datetime.timedelta(seconds=expires_in)
|
||||
expirydatetime = timezone.now()+timedelta(seconds=expires_in)
|
||||
|
||||
r = Rower.objects.get(user=user)
|
||||
r.rojabo_token = access_token
|
||||
@@ -167,3 +168,41 @@ def do_refresh_token(refreshtoken):
|
||||
refresh_token = 0
|
||||
|
||||
return [thetoken, expires_in, refresh_token]
|
||||
|
||||
aweekago = timezone.now()-timedelta(days=7)
|
||||
today = timezone.now()
|
||||
|
||||
def get_rojabo_workout_list(user,startdate=aweekago,enddate=today):
|
||||
r = Rower.objects.get(user=user)
|
||||
print(r.rojabo_tokenexpirydate)
|
||||
if (r.rojabo_token == '') or (r.rojabo_token is None): # pragma: no cover
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401, s)
|
||||
elif (timezone.now() > r.rojabo_tokenexpirydate): # pragma: no cover
|
||||
s = "Token expired. Needs to refresh."
|
||||
|
||||
return custom_exception_handler(401, s)
|
||||
|
||||
_ = rojabo_open(user)
|
||||
|
||||
authorizationstring = str('Bearer ' + r.rojabo_token)
|
||||
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'Content-Type': 'application/json'}
|
||||
|
||||
date1 = startdate.strftime('%Y-%m-%d')
|
||||
date2 = enddate.strftime('%Y-%m-%d')
|
||||
|
||||
|
||||
url = ROJABO_OAUTH_LOCATION+'api/v1/training_sessions?from={date1}&to={date2}'.format(date1=date1,date2=date2)
|
||||
|
||||
print(url)
|
||||
print(headers)
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
print(response.status_code,'aap')
|
||||
print(response.reason)
|
||||
print(response.json())
|
||||
|
||||
return response
|
||||
|
||||
@@ -1621,8 +1621,6 @@ def workout_getrp3workout_all(request): # pragma: no cover
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# List of workouts available on Concept2 logbook - for import
|
||||
|
||||
|
||||
@login_required()
|
||||
@permission_required('rower.is_coach', fn=get_user_by_userid, raise_exception=True)
|
||||
@permission_required('rower.is_not_freecoach', fn=get_user_by_userid, raise_exception=True)
|
||||
|
||||
Reference in New Issue
Block a user