Private
Public Access
1
0

Merge branch 'feature/c2repair' into develop

This commit is contained in:
Sander Roosendaal
2016-12-22 20:34:39 +01:00
3 changed files with 36 additions and 11 deletions
+33 -8
View File
@@ -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,19 @@ 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()
prepped.body+="&scope="
prepped.body+=scope
response = s.send(prepped)
token_json = response.json()
try:
thetoken = token_json['access_token']
@@ -263,17 +276,29 @@ 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,
}
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)
prepped = req.prepare()
prepped.body+="&scope="
prepped.body+=scope
response = s.send(prepped)
# response = requests.post("https://log.concept2.com/oauth/access_token",
# data=post_data,
# headers=headers)
token_json = response.json()
thetoken = token_json['access_token']
expires_in = token_json['expires_in']
@@ -286,13 +311,13 @@ 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",
"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)
url += "&scope="+scope
return HttpResponseRedirect(url)
+1 -1
View File
@@ -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
+2 -2
View File
@@ -1097,13 +1097,13 @@ 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",
"redirect_uri": C2_REDIRECT_URI}
import urllib
url = "http://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)
url += "&scope="+scope
return HttpResponseRedirect(url)
@login_required()