From e1eab77a526dd68f638764cadef645688e3bca68 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 25 Mar 2018 20:31:12 +0200 Subject: [PATCH] add workouttype & boattype to email processing --- rowers/management/commands/processemail.py | 1 + rowers/tests.py | 6 ++- rowers/uploads.py | 45 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 9b166bc1..bcb27787 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -72,6 +72,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False): workout = Workout.objects.get(id=workoutid[0]) uploads.do_sync(workout, uploadoptions) uploads.make_private(workout, uploadoptions) + uploads.set_workouttype(workout, uploadoptions) if 'make_plot' in uploadoptions: plottype = uploadoptions['plottype'] workoutcsvfilename = workout.csvfilename[6:-4] diff --git a/rowers/tests.py b/rowers/tests.py index 0e6df0f0..5fd5288b 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -362,7 +362,11 @@ class EmailTests(TestCase): from_header = u.email, subject = filename, body=""" - chart time +--- +chart: time +workouttype: water +boattype: 4x +... """) m.save() a2 = 'media/mailbox_attachments/'+filename diff --git a/rowers/uploads.py b/rowers/uploads.py index 2a760442..a5a4fc61 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -27,6 +27,8 @@ queue = django_rq.get_queue('default') queuelow = django_rq.get_queue('low') queuehigh = django_rq.get_queue('low') +from types import workouttypes,boattypes + try: from cStringIO import StringIO except: @@ -96,6 +98,29 @@ def matchsync(line): return results +def gettypeoptions_body2(uploadoptions,body): + tester = re.compile('^(workout)') + testerb = re.compile('^(boat)') + for line in body.splitlines(): + if tester.match(line.lower()): + for typ,verb in workouttypes: + str1 = '^(workout)(.*)({a})'.format( + a = typ + ) + testert = re.compile(str1) + if testert.match(line.lower()): + uploadoptions['workouttype'] = typ + if testerb.match(line.lower()): + for typ,verb in boattypes: + str1 = '^(boat)(.*)({a})'.format( + a = typ + ) + testert = re.compile(str1) + if testert.match(line.lower()): + uploadoptions['boattype'] = typ + + return uploadoptions + def getprivateoptions_body2(uploadoptions,body): tester = re.compile('^(priva)') for line in body.splitlines(): @@ -181,7 +206,6 @@ def getplotoptions(uploadoptions,value): return uploadoptions -from types import workouttypes,boattypes def gettype(uploadoptions,value,key): workouttype = 'rower' @@ -235,10 +259,10 @@ def upload_options(body): uploadoptions = getplotoptions(uploadoptions,value) if 'priva' in lowkey: uploadoptions = getboolean(uploadoptions,value,'makeprivate') - if 'type' in lowkey: + if 'workout' in lowkey: uploadoptions = gettype(uploadoptions,value,'workouttype') if 'boat' in lowkey: - uploadoptions = getboattype(uploadoptions,value,'workouttype') + uploadoptions = getboattype(uploadoptions,value,'boattype') except AttributeError: #pass raise yaml.YAMLError @@ -247,6 +271,7 @@ def upload_options(body): uploadoptions = getplotoptions_body2(uploadoptions,body) uploadoptions = getsyncoptions_body2(uploadoptions,body) uploadoptions = getprivateoptions_body2(uploadoptions,body) + typeoptions = gettypeoptions_body2(uploadoptions,body) except IOError: pm = exc.problem_mark strpm = str(pm) @@ -327,6 +352,20 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0): import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff import underarmourstuff,tpstuff +def set_workouttype(w,options): + try: + w.workouttype = options['workouttype'] + w.save() + except KeyError: + pass + try: + w.boattype = options['boattype'] + w.save() + except KeyError: + pass + + return 1 + def make_private(w,options): if 'makeprivate' in options and options['makeprivate']: w.privacy = 'hidden'