changed to v3-example for debugging
This commit is contained in:
@@ -41,6 +41,8 @@ from rowsandall_app.settings import (
|
|||||||
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
baseurl = 'https://polaraccesslink.com/v3-example'
|
||||||
|
|
||||||
# Custom exception handler, returns a 401 HTTP message
|
# Custom exception handler, returns a 401 HTTP message
|
||||||
# with exception details in the json data
|
# with exception details in the json data
|
||||||
def custom_exception_handler(exc,message):
|
def custom_exception_handler(exc,message):
|
||||||
@@ -114,7 +116,6 @@ def make_authorization_url():
|
|||||||
import urllib
|
import urllib
|
||||||
url = "https://flow.polar.com/oauth2/authorization" +urllib.urlencode(params)
|
url = "https://flow.polar.com/oauth2/authorization" +urllib.urlencode(params)
|
||||||
|
|
||||||
print url
|
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -138,19 +139,17 @@ def get_polar_workouts(user):
|
|||||||
'Authorization':authorizationstring,
|
'Authorization':authorizationstring,
|
||||||
}
|
}
|
||||||
|
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}/exercise-transactions'.format(
|
url = baseurl+'/users/{userid}/exercise-transactions'.format(
|
||||||
userid = r.polaruserid
|
userid = r.polaruserid
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
response = requests.post(url, headers=headers)
|
response = requests.post(url, headers=headers)
|
||||||
print url
|
|
||||||
print r.polartoken
|
|
||||||
print response.status_code
|
|
||||||
|
|
||||||
if response.status_code == 201:
|
if response.status_code == 201:
|
||||||
transactionid = response.json()['transaction-id']
|
transactionid = response.json()['transaction-id']
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}/exercise-transactions/{transactionid}'.format(
|
url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}'.format(
|
||||||
transactionid = transactionid,
|
transactionid = transactionid,
|
||||||
userid = r.polaruserid
|
userid = r.polaruserid
|
||||||
)
|
)
|
||||||
@@ -158,21 +157,29 @@ def get_polar_workouts(user):
|
|||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
exerciseurls = response.json()['exercises']
|
exerciseurls = response.json()['exercises']
|
||||||
|
print 'Found {n} workouts'.format(
|
||||||
|
n=len(exerciseurls)
|
||||||
|
)
|
||||||
for exerciseurl in exerciseurls:
|
for exerciseurl in exerciseurls:
|
||||||
response = requests.get(exerciseurl,headers=headers)
|
response = requests.get(exerciseurl,headers=headers)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
exercise_dict = response.json()
|
exercise_dict = response.json()
|
||||||
|
print response.json()
|
||||||
tcxuri = exerciseurl+'/tcx'
|
tcxuri = exerciseurl+'/tcx'
|
||||||
response = requests.get(tcxuri,headers=headers2)
|
response = requests.get(tcxuri,headers=headers2)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
filename = 'media/polarimport{id}.tcx'.format(
|
filename = 'media/polarimport{id}.tcx'.format(
|
||||||
id = exercise_dict['id']
|
id = exercise_dict['id']
|
||||||
)
|
)
|
||||||
with open(filename,'w') as fop:
|
print 'downloading workout {id} to {filename}'.format(
|
||||||
|
filename=filename,
|
||||||
|
id = exercise_dict['id']
|
||||||
|
)
|
||||||
|
with open(filename,'wb') as fop:
|
||||||
fop.write(response.text)
|
fop.write(response.text)
|
||||||
exercise_dict['filename'] = filename
|
exercise_dict['filename'] = filename
|
||||||
else:
|
else:
|
||||||
exercise_dict['filename'] = None
|
exercise_dict['filename'] = ''
|
||||||
|
|
||||||
exercise_list.append(exercise_dict)
|
exercise_list.append(exercise_dict)
|
||||||
|
|
||||||
@@ -202,7 +209,7 @@ def get_polar_user_info(user,physical=False):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if not physical:
|
if not physical:
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}'.format(
|
url = baseurl+'/users/{userid}'.format(
|
||||||
userid = r.polaruserid
|
userid = r.polaruserid
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -236,7 +243,7 @@ def get_polar_workout(user,id,transactionid):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}/exercise-transactions'.format(
|
url = baseurl+'/users/{userid}/exercise-transactions'.format(
|
||||||
userid = r.polaruserid
|
userid = r.polaruserid
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -245,7 +252,7 @@ def get_polar_workout(user,id,transactionid):
|
|||||||
|
|
||||||
if response.status_code == 201:
|
if response.status_code == 201:
|
||||||
transactionid = response.json()['transaction-id']
|
transactionid = response.json()['transaction-id']
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}/exercise-transactions/{transactionid}'.format(
|
url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}'.format(
|
||||||
transactionid = transactionid,
|
transactionid = transactionid,
|
||||||
userid = r.polaruserid
|
userid = r.polaruserid
|
||||||
)
|
)
|
||||||
@@ -259,16 +266,13 @@ def get_polar_workout(user,id,transactionid):
|
|||||||
exercise_dict = response.json()
|
exercise_dict = response.json()
|
||||||
thisid = exercise_dict['id']
|
thisid = exercise_dict['id']
|
||||||
if thisid == id:
|
if thisid == id:
|
||||||
url = 'https://polaraccesslink.com/v3/users/{userid}/exercise-transactions/{transactionid}/exercises/{exerciseid}/tcx'.format(
|
url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}/exercises/{exerciseid}/tcx'.format(
|
||||||
userid = r.polaruserid,
|
userid = r.polaruserid,
|
||||||
transactionid = transactionid,
|
transactionid = transactionid,
|
||||||
exerciseid = id
|
exerciseid = id
|
||||||
)
|
)
|
||||||
|
|
||||||
print "Get TCX"
|
|
||||||
print url
|
|
||||||
response = requests.get(url,headers = headers2)
|
response = requests.get(url,headers = headers2)
|
||||||
print response.status_code
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
print response.text
|
print response.text
|
||||||
|
|||||||
Reference in New Issue
Block a user