From 2a4d0100d294615c5cc6f8177048f9674830087c Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 26 Sep 2017 13:57:11 +0200 Subject: [PATCH] added sync options --- rowers/management/commands/processemail.py | 13 +++-- rowers/uploads.py | 61 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 31c88be4..31d338b9 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -75,10 +75,12 @@ class Command(BaseCommand): if uploadoptions and not 'error' in uploadoptions: w = Workout.objects.get(wid[0]) r = w.user + uploads.do_sync(w,uploadoptions) if 'make_plot' in uploadoptions: plottype = uploadoptions['plottype'] - res = uploads.make_plot(r,w,plottype, - title,f2[6:],f2) + res = uploads.make_plot(r,w,f2[6:], + w.csvfilename, + plottype,title) try: if wid != 1: dd = send_confirm(rr.user,title,link, @@ -106,10 +108,13 @@ class Command(BaseCommand): if uploadoptions: w = Workout.objects.get(wid[0]) r = w.user + uploads.do_sync(w,uploadoptions) if 'make_plot' in uploadoptions: plottype = uploadoptions['plottype'] - res = uploads.make_plot(r,w,plottype, - title,f2[6:],f2) + res = uploads.make_plot(r,w,a.document, + w.csvfilename, + plottype,name) + except: # replace with code to process error diff --git a/rowers/uploads.py b/rowers/uploads.py index 245acfe5..ae4dbf61 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -176,3 +176,64 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0): i.save() return i.id + +import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff +import underarmourstuff,tpstuff + +def do_sync(w,options): + if 'upload_to_C2' in options and options['upload_to_C2']: + try: + message,id = c2stuff.workout_c2_upload(w.user.user,w) + except C2NoTokenError: + id = 0 + message = "Something went wrong with the Concept2 sync" + + if 'upload_to_Strava' in options and options['upload_to_Strava']: + try: + message,id = stravastuff.workout_strava_upload( + w.user.user,w + ) + except StravaNoTokenError: + id = 0 + message = "Please connect to Strava first" + + + if 'upload_to_SportTracks' in options and options['upload_to_SportTracks']: + try: + message,id = sporttracksstuff.workout_sporttracks_upload( + w.user.user,w + ) + except SportTracksNoTokenError: + message = "Please connect to SportTracks first" + id = 0 + + + if 'upload_to_RunKeeper' in options and options['upload_to_RunKeeper']: + try: + message,id = runkeeperstuff.workout_runkeeper_upload( + w.user.user,w + ) + except RunKeeperNoTokenError: + message = "Please connect to Runkeeper first" + id = 0 + + if 'upload_to_MapMyFitness' in options and options['upload_to_MapMyFitness']: + try: + message,id = underarmourstuff.workout_ua_upload( + w.user.user,w + ) + except UnderArmourNoTokenError: + message = "Please connect to MapMyFitness first" + id = 0 + + + if 'upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']: + try: + message,id = tpstuff.workout_tp_upload( + w.user.user,w + ) + except TPNoTokenError: + message = "Please connect to TrainingPeaks first" + id = 0 + + return 1