passing all tests on py3
This commit is contained in:
@@ -16,6 +16,8 @@ import rowers.mytypes as mytypes
|
||||
from rowers.mytypes import otwtypes
|
||||
from iso8601 import ParseError
|
||||
|
||||
import numpy
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET
|
||||
)
|
||||
@@ -424,7 +426,11 @@ def createc2workoutdata(w):
|
||||
hr = 0*d
|
||||
stroke_data = []
|
||||
for i in range(len(t)):
|
||||
thisrecord = {"t":t[i],"d":d[i],"p":p[i],"spm":spm[i],"hr":hr[i]}
|
||||
thisrecord = {"t":t[i].astype(int),
|
||||
"d":d[i].astype(int),
|
||||
"p":p[i].astype(int),
|
||||
"spm":spm[i].astype(int),
|
||||
"hr":hr[i].astype(int)}
|
||||
stroke_data.append(thisrecord)
|
||||
|
||||
try:
|
||||
@@ -440,7 +446,7 @@ def createc2workoutdata(w):
|
||||
startdatetime = w.startdatetime.isoformat()
|
||||
except AttributeError:
|
||||
startdate = datetime.datetime.combine(w.date,datetime.time())
|
||||
|
||||
|
||||
data = {
|
||||
"type": mytypes.c2mapping[workouttype],
|
||||
"date": w.startdatetime.isoformat(),
|
||||
@@ -551,7 +557,7 @@ def make_authorization_url(request):
|
||||
params = {"client_id": C2_CLIENT_ID,
|
||||
"response_type": "code",
|
||||
"redirect_uri": C2_REDIRECT_URI}
|
||||
url = "https://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)
|
||||
url = "https://log.concept2.com/oauth/authorize?"+ urllib.parse.urlencode(params)
|
||||
url += "&scope="+scope
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
@@ -697,6 +703,10 @@ def process_callback(request):
|
||||
|
||||
return HttpResponse("got a user name: %s" % username)
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
# Uploading workout
|
||||
def workout_c2_upload(user,w):
|
||||
message = 'trying C2 upload'
|
||||
@@ -717,6 +727,7 @@ def workout_c2_upload(user,w):
|
||||
raise NoTokenError
|
||||
|
||||
data = createc2workoutdata(w)
|
||||
|
||||
if data == 0:
|
||||
return "Error: No data file. Contact info@rowsandall.com if the problem persists",0
|
||||
|
||||
@@ -726,7 +737,7 @@ def workout_c2_upload(user,w):
|
||||
'Content-Type': 'application/json'}
|
||||
import urllib
|
||||
url = "https://log.concept2.com/api/users/%s/results" % (c2userid)
|
||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
||||
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||
|
||||
if (response.status_code == 409 ):
|
||||
message = "Concept2 Duplicate error"
|
||||
|
||||
Reference in New Issue
Block a user