Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-18 12:59:18 +01:00
parent f80dbdb4de
commit 508ebfd9a1
5 changed files with 87 additions and 115 deletions

View File

@@ -82,7 +82,7 @@ def strava_open(user):
f.write('\n')
token = imports_open(user, oauth_data)
if user.rower.strava_owner_id == 0: # pragma: no cover
strava_owner_id = set_strava_athlete_id(user)
_ = set_strava_athlete_id(user)
return token
@@ -120,9 +120,6 @@ def strava_establish_push(): # pragma: no cover
'callback_url': webhooklink,
'verify_token': webhookverification,
}
headers = {'user-agent': 'sanderroosendaal',
'Accept': 'application/json',
'Content-Type': oauth_data['content_type']}
response = requests.post(url, data=post_data)
@@ -160,7 +157,7 @@ def set_strava_athlete_id(user):
s = "Token doesn't exist. Need to authorize"
return custom_exception_handler(401, s)
elif (r.stravatokenexpirydate is None or timezone.now()+timedelta(seconds=3599) > r.stravatokenexpirydate):
token = imports_open(user, oauth_data)
_ = imports_open(user, oauth_data)
authorizationstring = str('Bearer ' + r.stravatoken)
headers = {'Authorization': authorizationstring,
@@ -185,7 +182,9 @@ def get_strava_workout_list(user, limit_n=0):
if (r.stravatoken == '') or (r.stravatoken is None): # pragma: no cover
s = "Token doesn't exist. Need to authorize"
return custom_exception_handler(401, s)
elif (r.stravatokenexpirydate is None or timezone.now()+timedelta(seconds=3599) > r.stravatokenexpirydate): # pragma: no cover
elif (
r.stravatokenexpirydate is None or timezone.now()+timedelta(seconds=3599) > r.stravatokenexpirydate
): # pragma: no cover
s = "Token expired. Needs to refresh."
return custom_exception_handler(401, s)
else:
@@ -209,7 +208,7 @@ def get_strava_workout_list(user, limit_n=0):
def async_get_workout(user, stravaid):
try:
token = strava_open(user)
_ = strava_open(user)
except NoTokenError: # pragma: no cover
return 0
@@ -246,9 +245,9 @@ def createstravaworkoutdata(w, dozip=True):
if datalength != 0:
data.rename(columns=columndict, inplace=True)
res = data.to_csv(w.csvfilename+'.gz',
index_label='index',
compression='gzip')
_ = data.to_csv(w.csvfilename+'.gz',
index_label='index',
compression='gzip')
try:
row = rowingdata(csvfile=filename)
except IOError:
@@ -317,7 +316,7 @@ def handle_stravaexport(f2, workoutname, stravatoken, description='',
def workout_strava_upload(user, w, quick=False, asynchron=True):
try:
thetoken = strava_open(user)
_ = strava_open(user)
except NoTokenError: # pragma: no cover
return "Please connect to Strava first", 0
@@ -326,7 +325,6 @@ def workout_strava_upload(user, w, quick=False, asynchron=True):
r = Rower.objects.get(user=user)
res = -1
if (r.stravatoken == '') or (r.stravatoken is None): # pragma: no cover
s = "Token doesn't exist. Need to authorize"
raise NoTokenError("Your hovercraft is full of eels")
if (is_workout_user(user, w)):
@@ -340,13 +338,12 @@ def workout_strava_upload(user, w, quick=False, asynchron=True):
activity_type = mytypes.stravamapping[w.workouttype]
except KeyError: # pragma: no cover
activity_type = 'Rowing'
job = myqueue(queue,
handle_strava_sync,
r.stravatoken,
w.id,
tcxfile, w.name, activity_type,
w.notes
)
_ = myqueue(queue,
handle_strava_sync,
r.stravatoken,
w.id,
tcxfile, w.name, activity_type,
w.notes)
dologging('strava_export_log.log', 'Exporting as {t} from {w}'.format(
t=activity_type, w=w.workouttype))
return "Asynchronous sync", -1