sporttracks and strava warning when no data
This commit is contained in:
@@ -176,7 +176,11 @@ def get_sporttracks_workout(user,sporttracksid):
|
|||||||
|
|
||||||
def createsporttracksworkoutdata(w):
|
def createsporttracksworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
row = rowingdata(filename)
|
try:
|
||||||
|
row = rowingdata(filename)
|
||||||
|
except:
|
||||||
|
return 0
|
||||||
|
|
||||||
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
||||||
maxhr = int(row.df[' HRCur (bpm)'].max())
|
maxhr = int(row.df[' HRCur (bpm)'].max())
|
||||||
|
|
||||||
|
|||||||
@@ -238,9 +238,12 @@ def get_strava_workout(user,stravaid):
|
|||||||
|
|
||||||
def createstravaworkoutdata(w):
|
def createstravaworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
row = rowingdata(filename)
|
try:
|
||||||
tcxfilename = filename[:-4]+'.tcx'
|
row = rowingdata(filename)
|
||||||
row.exporttotcx(tcxfilename,notes=w.notes)
|
tcxfilename = filename[:-4]+'.tcx'
|
||||||
|
row.exporttotcx(tcxfilename,notes=w.notes)
|
||||||
|
except:
|
||||||
|
tcxfilename = 0
|
||||||
|
|
||||||
return tcxfilename
|
return tcxfilename
|
||||||
|
|
||||||
|
|||||||
@@ -924,34 +924,42 @@ def workout_strava_upload_view(request,id=0):
|
|||||||
if (checkworkoutuser(request.user,w)):
|
if (checkworkoutuser(request.user,w)):
|
||||||
try:
|
try:
|
||||||
tcxfile = stravastuff.createstravaworkoutdata(w)
|
tcxfile = stravastuff.createstravaworkoutdata(w)
|
||||||
|
if tcxfile:
|
||||||
with open(tcxfile,'rb') as f:
|
with open(tcxfile,'rb') as f:
|
||||||
try:
|
try:
|
||||||
res = stravastuff.handle_stravaexport(f,w.name,
|
res = stravastuff.handle_stravaexport(f,w.name,
|
||||||
r.stravatoken,
|
r.stravatoken,
|
||||||
description=w.notes)
|
description=w.notes)
|
||||||
except:
|
except:
|
||||||
with open("media/stravaerrors.log","a") as errorlog:
|
with open("media/stravaerrors.log","a") as errorlog:
|
||||||
errorstring = str(sys.exc_info()[0])
|
errorstring = str(sys.exc_info()[0])
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
errorlog.write(timestr+errorstring+"\r\n")
|
errorlog.write(timestr+errorstring+"\r\n")
|
||||||
errorlog.write("views.py line 937\r\n")
|
errorlog.write("views.py line 937\r\n")
|
||||||
message = 'Error: '+errorstring
|
message = 'Error: '+errorstring
|
||||||
res = 0
|
res = 0
|
||||||
try:
|
try:
|
||||||
w.uploadedtostrava = res
|
w.uploadedtostrava = res
|
||||||
w.save()
|
w.save()
|
||||||
os.remove(tcxfile)
|
os.remove(tcxfile)
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
url = "/rowers/workout/"+str(w.id)+"/edit"
|
||||||
successmessage = 'Workout sent to Strava.'
|
successmessage = 'Workout sent to Strava.'
|
||||||
except:
|
except:
|
||||||
with open("media/stravaerrors.log","a") as errorlog:
|
with open("media/stravaerrors.log","a") as errorlog:
|
||||||
errorstring = str(sys.exc_info()[0])
|
errorstring = str(sys.exc_info()[0])
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
errorlog.write(timestr+errorstring+"\r\n")
|
errorlog.write(timestr+errorstring+"\r\n")
|
||||||
errorlog.write("views.py line 952\r\n")
|
errorlog.write("views.py line 952\r\n")
|
||||||
message = 'Error: '+errorstring
|
message = 'Error: '+errorstring
|
||||||
|
else:
|
||||||
|
message = "Strava Upload error"
|
||||||
|
w.uploadedtostrava = -1
|
||||||
|
w.save()
|
||||||
|
url = reverse(workout_export_view,
|
||||||
|
kwargs = {
|
||||||
|
'id':str(w.id),
|
||||||
|
})
|
||||||
|
response = HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
url = reverse(workout_export_view,
|
url = reverse(workout_export_view,
|
||||||
@@ -1063,6 +1071,15 @@ def workout_sporttracks_upload_view(request,id=0):
|
|||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
if (checkworkoutuser(request.user,w)):
|
if (checkworkoutuser(request.user,w)):
|
||||||
data = sporttracksstuff.createsporttracksworkoutdata(w)
|
data = sporttracksstuff.createsporttracksworkoutdata(w)
|
||||||
|
if not data:
|
||||||
|
message = "Data error"
|
||||||
|
url = reverse(workout_export_view,
|
||||||
|
kwargs = {
|
||||||
|
'message':str(message),
|
||||||
|
'id':str(w.id),
|
||||||
|
})
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
authorizationstring = str('Bearer ' + thetoken)
|
authorizationstring = str('Bearer ' + thetoken)
|
||||||
headers = {'Authorization': authorizationstring,
|
headers = {'Authorization': authorizationstring,
|
||||||
'user-agent': 'sanderroosendaal',
|
'user-agent': 'sanderroosendaal',
|
||||||
|
|||||||
Reference in New Issue
Block a user