diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 0d0fedfd..1ba4c03d 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -24,6 +24,9 @@ import pandas as pd import numpy as np from rowers.models import Rower,Workout import sys +import urllib +from requests import Request, Session + from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET @@ -233,6 +236,7 @@ def createc2workoutdata(w): return data def do_refresh_token(refreshtoken): + scope = "results:write,user:read" client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET) post_data = {"grant_type": "refresh_token", "client_secret": C2_CLIENT_SECRET, @@ -240,10 +244,25 @@ def do_refresh_token(refreshtoken): "refresh_token": refreshtoken, } headers = {'user-agent': 'sanderroosendaal'} - response = requests.post("https://log.concept2.com/oauth/access_token", - data=post_data, - headers=headers) + url = "https://log.concept2.com/oauth/access_token" + s = Session() + req = Request('POST',url, data=post_data, headers=headers) + # response = requests.post("https://log.concept2.com/oauth/access_token", + # data=post_data, + # data=post_data, + # headers=headers) + + prepped = req.prepare() + print prepped.body + prepped.body+="&scope=" + prepped.body+=scope + print prepped.body + + response = s.send(prepped) + print response.status_code + + print response token_json = response.json() try: thetoken = token_json['access_token'] @@ -263,9 +282,11 @@ def do_refresh_token(refreshtoken): def get_token(code): + scope = "user:read,results:write" client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET) post_data = {"grant_type": "authorization_code", "code": code, + "scope": scope, "redirect_uri": C2_REDIRECT_URI, "client_secret": C2_CLIENT_SECRET, "client_id":C2_CLIENT_ID, @@ -286,11 +307,12 @@ def make_authorization_url(request): # Save it for use later to prevent xsrf attacks from uuid import uuid4 state = str(uuid4()) + scope = "user:read,results:write" params = {"client_id": CLIENT_ID, "response_type": "code", + "scope":scope, "redirect_uri": REDIRECT_URI} - import urllib url = "https://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params) # url = "https://ssl.reddit.com/api/v1/authorize?" + urllib.urlencode(params) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index e942da7e..9744b6b9 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -518,7 +518,7 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, try: drivespeed = drivelength/rowdatadf[' DriveTime (ms)']*1.0e3 except TypeError: - drivespeed = 0.0*drivelength + drivespeed = 0.0*rowdatadf['TimeStam (sec)'] drivespeed = drivespeed.fillna(value=0) driveenergy = drivelength*averageforce*4.44822 diff --git a/rowers/views.py b/rowers/views.py index 35b3233d..3a57a324 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1095,9 +1095,11 @@ def rower_c2_authorize(request): # Save it for use later to prevent xsrf attacks from uuid import uuid4 state = str(uuid4()) + scope = "user:read,results:write" params = {"client_id": C2_CLIENT_ID, "response_type": "code", + "scope":scope, "redirect_uri": C2_REDIRECT_URI} import urllib url = "http://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)