Private
Public Access
1
0

logging for strava webhooks

This commit is contained in:
Sander Roosendaal
2020-07-12 16:22:33 +02:00
parent ddebc60f14
commit fb8ba401a8

View File

@@ -1019,6 +1019,15 @@ def strava_webhook_view(request):
data = {"hub.challenge":challenge}
return JSONResponse(data)
# logging
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
with open('strava_webhooks.log','a') as f:
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write(str(request.body))
# POST - does nothing so far
data = json.loads(request.body)
try:
@@ -1027,6 +1036,12 @@ def strava_webhook_view(request):
strava_owner = data['owner_id']
starttimeunix = data['event_time']
except KeyError:
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
with open('strava_webhooks.log','a') as f:
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write('KeyError line 1038')
return HttpResponse(status=200)
if aspect_type == 'create':
@@ -1034,11 +1049,23 @@ def strava_webhook_view(request):
try:
stravaid = data['object_id']
except KeyError:
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
with open('strava_webhooks.log','a') as f:
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write('KeyError line 1051')
return HttpResponse(status=200)
try:
r = Rower.objects.get(strava_owner_id=strava_owner)
except Rower.DoesNotExist:
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
with open('strava_webhooks.log','a') as f:
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write('Rower not found')
return HttpResponse(status=200)
# too slow ...