First attempt at processing strava webhook create
This commit is contained in:
@@ -1009,6 +1009,7 @@ def workout_stravaimport_view(request,message="",userid=0):
|
||||
return HttpResponse(res)
|
||||
|
||||
# for Strava webhook request validation
|
||||
@csrf_exempt
|
||||
def strava_webhook_view(request):
|
||||
if request.method == 'GET':
|
||||
challenge = request.GET.get('hub.challenge')
|
||||
@@ -1019,6 +1020,39 @@ def strava_webhook_view(request):
|
||||
return JSONResponse(data)
|
||||
|
||||
# POST - does nothing so far
|
||||
data = json.loads(request.body)
|
||||
try:
|
||||
aspect_type = data['aspect_type']
|
||||
object_type = data['object_type']
|
||||
strava_owner = data['owner_id']
|
||||
starttimeunix = data['event_time']
|
||||
except KeyError:
|
||||
return HttpResponse(status=200)
|
||||
|
||||
if aspect_type == 'create':
|
||||
if object_type == 'activity':
|
||||
try:
|
||||
stravaid = data['object_id']
|
||||
except KeyError:
|
||||
return HttpResponse(status=200)
|
||||
|
||||
try:
|
||||
r = Rower.objects.get(strava_owner_id=strava_owner)
|
||||
except Rower.DoesNotExist:
|
||||
return HttpResponse(status=200)
|
||||
|
||||
w = Workout(
|
||||
user = r,
|
||||
csvfilename = 'media/{code}_{stravaid}'.format(code=uuid4().hex[:16],stravaid=stravaid),
|
||||
startdatetime = timezone.now(),
|
||||
uploadedtostrava=stravaid,
|
||||
)
|
||||
w.save()
|
||||
# too slow ...
|
||||
job = stravastuff.async_get_workout(r.user,stravaid,w)
|
||||
|
||||
print(w.id)
|
||||
|
||||
return HttpResponse(status=200)
|
||||
|
||||
# For push notifications from Garmin
|
||||
|
||||
Reference in New Issue
Block a user