Private
Public Access
1
0

more logging for polar

This commit is contained in:
Sander Roosendaal
2022-01-03 20:10:19 +01:00
parent 60e0da290c
commit 8993f3cbb6

View File

@@ -135,12 +135,16 @@ def get_polar_notifications(): # pragma: no cover
'status_code':400,
}
dologging('polar.log',response)
available_data = []
try:
if response.status_code == 200:
available_data = response.json()['available-user-data']
dologging('polar.log',available_data)
except AttributeError:
dologging('polar.log',response.text)
pass
return available_data
@@ -158,6 +162,7 @@ def get_all_new_workouts(available_data,testing=False):
u = r.user
if r.polar_auto_import and ispromember(u):
exercise_list = get_polar_workouts(u)
dologging('polar.log',exercise_list)
if testing:
print(exercise_list)
except Rower.DoesNotExist:
@@ -176,6 +181,7 @@ def get_polar_workouts(user):
return custom_exception_handler(401,s)
elif (timezone.now()>r.polartokenexpirydate): # pragma: no cover
s = "Token expired. Needs to refresh"
dologging('polar.log',s)
return custom_exception_handler(401,s)
else: # pragma: no cover
authorizationstring = str('Bearer ' + r.polartoken)
@@ -192,6 +198,8 @@ def get_polar_workouts(user):
response = requests.post(url, headers=headers)
dologging('polar.log',url)
dologging('polar.log',response.status_code)
if response.status_code == 201:
@@ -214,6 +222,7 @@ def get_polar_workouts(user):
response = requests.get(url, headers=headers)
if response.status_code == 200:
exerciseurls = response.json()['exercises']
dologging('polar.log',exerciseurls)
for exerciseurl in exerciseurls:
response = requests.get(exerciseurl,headers=headers)
if response.status_code == 200:
@@ -225,6 +234,7 @@ def get_polar_workouts(user):
id = exercise_dict['id'],
code = uuid4().hex[:16]
)
dologging('polar.log',filename)
with open(filename,'wb') as fop:
fop.write(response.content)