Private
Public Access
1
0

adding simple export to Garmin

This commit is contained in:
Sander Roosendaal
2021-05-16 15:33:03 +02:00
parent 54190ed383
commit cbf7c4ab0b
9 changed files with 92 additions and 15 deletions

View File

@@ -11,6 +11,8 @@ from rowers.mytypes import otwtypes
from rowers.rower_rules import is_workout_user,ispromember
from iso8601 import ParseError
from rowers.plannedsessions import ps_dict_get_description
import pandas as pd
@@ -131,6 +133,7 @@ def garmin_processcallback(redirect_response,resource_owner_key,resource_owner_s
verifier = oauth_response.get('oauth_verifier')
token = oauth_response.get('oauth_token')
access_token_url = 'https://connectapi.garmin.com/oauth-service/oauth/access_token'
print(token,access_token_url)
# Using OAuth1Session
garmin = OAuth1Session(oauth_data['client_id'],
@@ -191,6 +194,8 @@ def get_garmin_workout_list(user): # pragma: no cover
return result
def garmin_can_export_session(user): # pragma: no cover
if user.rower.rowerplan not in ['coach','plan']:
return False
result = get_garmin_permissions(user)
if 'WORKOUT_IMPORT' in result:
return True
@@ -254,7 +259,6 @@ def step_to_garmin(step,order=0):
except KeyError:
targetType = None
try:
targetValue = step['dict']['targetValue']
if targetValue == 0:
@@ -283,6 +287,13 @@ def step_to_garmin(step,order=0):
if targetValueLow is not None and targetValueLow > 1000:
targetValueLow -= 1000
# temp - throw away target other than power
if targetType.lower() != 'power':
targetType = None
targetValue = None
targetValueLow = None
targetValueHigh = None
if targetValue is None and targetValueLow is None and targetValueHigh is None:
targetType = None
@@ -333,8 +344,8 @@ def step_to_garmin(step,order=0):
def ps_to_garmin(ps,r):
payload = {
'workoutName': ps.name,
'sport': 'GENERIC',
'description':'Uploaded from Rowsandall.com',
'sport':r.garminactivity,
'description':ps_dict_get_description(ps.steps),
'estimatedDurationInSecs':60*ps.approximate_duration,
'estimatedDistanceInMeters': ps.approximate_distance,
'workoutProvider': 'Rowsandall.com',
@@ -390,12 +401,13 @@ def get_garmin_permissions(user): # pragma: no cover
def garmin_session_create(ps,user): # pragma: no cover
if not ps.steps:
print('aap')
return 0
if not garmin_can_export_session(user):
print('noot')
return 0
if ps.garmin_schedule_id != 0:
return ps.garmin_schedule_id
r = Rower.objects.get(user=user)
if (r.garmintoken == '') or (r.garmintoken is None):
s = "Token doesn't exist. Need to authorize"
@@ -414,7 +426,7 @@ def garmin_session_create(ps,user): # pragma: no cover
)
response = requests.post(url,auth=garminheaders,json=payload)
print(response.status_code,response.text)
if response.status_code != 200:
@@ -432,7 +444,6 @@ def garmin_session_create(ps,user): # pragma: no cover
response = requests.post(url,auth=garminheaders,json=payload)
print(response.status_code,response.text)
if response.status_code != 200:
return 0