Private
Public Access
1
0

fix errors tcx

This commit is contained in:
2023-11-20 19:06:11 +01:00
parent c237e3cde4
commit 34499ae287
3 changed files with 52 additions and 40 deletions

View File

@@ -128,6 +128,8 @@ def send_template_email(from_email, to_email, subject,
umsg.save() umsg.save()
except User.DoesNotExist: except User.DoesNotExist:
pass pass
except Exception as e:
pass
if not emailbounced: if not emailbounced:
res = msg.send() res = msg.send()

Binary file not shown.

View File

@@ -15,7 +15,7 @@ from datetime import datetime as dt
import rowingdata.tcxtools as tcxtools import rowingdata.tcxtools as tcxtools
from rowingdata import TCXParser, rowingdata from rowingdata import TCXParser, rowingdata
import arrow
class XMLParser(BaseParser): class XMLParser(BaseParser):
media_type = "application/xml" media_type = "application/xml"
@@ -239,12 +239,14 @@ def strokedata_tcx(request):
Upload a TCX file through API Upload a TCX file through API
""" """
if request.method != 'POST': if request.method != 'POST':
dologging('apilog.log','GET request to TCX endpoint')
return HttpResponseNotAllowed("Method not supported") # pragma: no cover return HttpResponseNotAllowed("Method not supported") # pragma: no cover
if request.content_type.lower() != 'application/xml': if request.content_type.lower() != 'application/xml':
dologging('apilog.log','POST data not application/xml, request to TCX endpoint')
return HttpResponseNotAllowed("Need application/xml") return HttpResponseNotAllowed("Need application/xml")
dologging('apilog.log', request.user.username+" (strokedatajson_TCX POST)") dologging('apilog.log', request.user.username+" (strokedata_tcx POST)")
try: try:
tcxdata = request.data tcxdata = request.data
@@ -267,10 +269,12 @@ def strokedata_tcx(request):
total_duration += lap_duration_seconds total_duration += lap_duration_seconds
except Exception as e: except Exception as e:
dologgin('apilog.log','TCX')
dologging('apilog.log',e) dologging('apilog.log',e)
return HttpResponseNotAllowed("Could not parse TCX data") return HttpResponseNotAllowed("Could not parse TCX data")
try:
tcxfilename = 'media/{code}.tcx'.format(code=uuid4().hex[:16]) tcxfilename = 'media/{code}.tcx'.format(code=uuid4().hex[:16])
xml_string = ET.tostring(tcxdata, encoding='utf-8', method='xml').decode('utf-8') xml_string = ET.tostring(tcxdata, encoding='utf-8', method='xml').decode('utf-8')
@@ -279,7 +283,8 @@ def strokedata_tcx(request):
duration = totaltime_sec_to_string(total_duration) duration = totaltime_sec_to_string(total_duration)
startdatetime = dt.strptime(start_time_str, "%Y-%m-%dT%H:%M:%S%z") startdatetime = arrow.get(start_time_str)
#startdatetime = dt.strptime(start_time_str, "%Y-%m-%dT%H:%M:%S%z")
startdate = startdatetime.date() startdate = startdatetime.date()
partofday = part_of_day(startdatetime.hour) partofday = part_of_day(startdatetime.hour)
title = '{partofday} water'.format(partofday=partofday) title = '{partofday} water'.format(partofday=partofday)
@@ -317,6 +322,11 @@ def strokedata_tcx(request):
"workout id": workoutid, "workout id": workoutid,
"status": "success", "status": "success",
}) })
except Exception as e:
dologging('apilog.log','TCX API endpoint')
dologging('apilog.log',e)
return HttpResponse(status=500)