From 64da35a6f8c03bef8fe72e40f0a24563a6d1ead6 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 19 Apr 2017 08:11:51 +0200 Subject: [PATCH] Strava uploads now use gzip --- rowers/stravastuff.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 5fd018c4..1323f03b 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -14,6 +14,7 @@ import time import math from math import sin,cos,atan2,sqrt import os,sys +import gzip # Django from django.shortcuts import render_to_response @@ -230,6 +231,13 @@ def createstravaworkoutdata(w): row = rowingdata(filename) tcxfilename = filename[:-4]+'.tcx' row.exporttotcx(tcxfilename,notes=w.notes) + gzfilename = tcxfilename+'.gz' + with file(tcxfilename,'rb') as inF: + s = inF.read() + with gzip.GzipFile(gzfilename,'wb') as outF: + outF.write(s) + os.remove(tcxfilename) + return gzfilename except: tcxfilename = 0 @@ -241,7 +249,7 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): # w = Workout.objects.get(id=workoutid) client = stravalib.Client(access_token=stravatoken) - act = client.upload_activity(f2,'tcx',name=workoutname) + act = client.upload_activity(f2,'tcx.gz',name=workoutname) try: res = act.wait(poll_interval=5.0,timeout=30) message = 'Workout successfully synchronized to Strava'