basic processing of upload options from email
This commit is contained in:
@@ -15,6 +15,7 @@ import yaml
|
|||||||
import argparse
|
import argparse
|
||||||
import yamllint
|
import yamllint
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
@@ -26,17 +27,80 @@ from rowers.utils import (
|
|||||||
str2bool,range_to_color_hex,absolute
|
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):
|
def upload_options(body):
|
||||||
uploadoptions = {}
|
uploadoptions = {}
|
||||||
# ok, a temp solution - write to temp file
|
body = cleanbody(body)
|
||||||
with open('temp.txt','w') as f:
|
try:
|
||||||
f.write(body)
|
yml = (yaml.load(body))
|
||||||
with open('temp.txt','r') as f:
|
for key, value in yml.iteritems():
|
||||||
try:
|
if key == 'sync' or key == 'synchronization':
|
||||||
yml = (yaml.load(f))
|
uploadoptions = getsyncoptions(uploadoptions,value)
|
||||||
print yml
|
if key == 'chart' or key == 'static' or key == 'plot':
|
||||||
except yaml.YAMLError as exc:
|
uploadoptions = getplotoptions(uploadoptions,value)
|
||||||
call(["yamllint","-f","parsable",'temp.txt'])
|
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
|
return uploadoptions
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user