basic processing of upload options from email
This commit is contained in:
@@ -15,6 +15,7 @@ import yaml
|
||||
import argparse
|
||||
import yamllint
|
||||
from subprocess import call
|
||||
import re
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
@@ -26,17 +27,80 @@ from rowers.utils import (
|
||||
str2bool,range_to_color_hex,absolute
|
||||
)
|
||||
|
||||
def cleanbody(body):
|
||||
p = re.compile('.*---\n([\s\S]*)...')
|
||||
m = p.match(body)
|
||||
if m != None:
|
||||
body = m.group(1)
|
||||
|
||||
return body
|
||||
|
||||
def getsyncoptions(uploadoptions,values):
|
||||
try:
|
||||
value = values.lower()
|
||||
values = [values]
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
for v in values:
|
||||
try:
|
||||
v = v.lower()
|
||||
|
||||
if v in ['c2','concept2','logbook']:
|
||||
uploadoptions['upload_to_C2'] = True
|
||||
if v in ['tp','trainingpeaks']:
|
||||
uploadoptions['upload_totp'] = True
|
||||
if v in ['strava']:
|
||||
uploadoptions['upload_to_Strava'] = True
|
||||
if v in ['st','sporttracks']:
|
||||
uploadoptions['upload_to_SportTracks'] = True
|
||||
if v in ['rk','runkeeper']:
|
||||
uploadoptions['upload_to_RunKeeper'] = True
|
||||
if v in ['ua','underarmour','mapmyfitness']:
|
||||
uploadoptions['upload_to_MapMyFitness'] = True
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def getplotoptions(uploadoptions,value):
|
||||
try:
|
||||
v = value.lower()
|
||||
if v in ['pieplot','timeplot','distanceplot']:
|
||||
uploadoptions['make_plot'] = True
|
||||
uploadoptions['plottype'] = v
|
||||
elif 'pie' in v:
|
||||
uploadoptions['make_plot'] = True
|
||||
uploadoptions['plottype'] = 'pieplot'
|
||||
elif 'distance' in v:
|
||||
uploadoptions['make_plot'] = True
|
||||
uploadoptions['plottype'] = 'distanceplot'
|
||||
elif 'time' in v:
|
||||
uploadoptions['make_plot'] = True
|
||||
uploadoptions['plottype'] = 'timeplot'
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def upload_options(body):
|
||||
uploadoptions = {}
|
||||
# ok, a temp solution - write to temp file
|
||||
with open('temp.txt','w') as f:
|
||||
f.write(body)
|
||||
with open('temp.txt','r') as f:
|
||||
try:
|
||||
yml = (yaml.load(f))
|
||||
print yml
|
||||
except yaml.YAMLError as exc:
|
||||
call(["yamllint","-f","parsable",'temp.txt'])
|
||||
body = cleanbody(body)
|
||||
try:
|
||||
yml = (yaml.load(body))
|
||||
for key, value in yml.iteritems():
|
||||
if key == 'sync' or key == 'synchronization':
|
||||
uploadoptions = getsyncoptions(uploadoptions,value)
|
||||
if key == 'chart' or key == 'static' or key == 'plot':
|
||||
uploadoptions = getplotoptions(uploadoptions,value)
|
||||
except yaml.YAMLError as exc:
|
||||
pm = exc.problem_mark
|
||||
strpm = str(pm)
|
||||
pbm = "Your email has an issue on line {} at position {}. The error is: ".format(
|
||||
pm.line+1,
|
||||
pm.column+1,
|
||||
)+strpm
|
||||
return {'error':pbm}
|
||||
|
||||
return uploadoptions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user