alternative natural language for plot,sync,privacy
This commit is contained in:
@@ -19,8 +19,8 @@ import yamllint
|
|||||||
from subprocess import call
|
from subprocess import call
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from verbal_expressions import VerEx
|
from verbalexpressions import VerEx
|
||||||
|
import re
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
@@ -48,28 +48,84 @@ def cleanbody(body):
|
|||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
# currently only matches one chart
|
||||||
def matchchart(line):
|
def matchchart(line):
|
||||||
results = []
|
results = []
|
||||||
tester = VerEx().start_of_line().find('chart')
|
tester = VerEx().start_of_line().find('chart').OR().find('plot')
|
||||||
tester2 = VerEx().start_of_line().find('chart').anything().find('distance')
|
tester2 = VerEx().start_of_line().find('chart').OR().find('plot').anything().find('distance')
|
||||||
tester3 = VerEx().start_of_line().find('chart').anything().find('time')
|
tester3 = VerEx().start_of_line().find('chart').OR().find('plot').anything().find('time')
|
||||||
tester4 = VerEx().start_of_line().find('chart').anything().find('pie')
|
tester4 = VerEx().start_of_line().find('chart').OR().find('plot').anything().find('pie')
|
||||||
if tester.match(line):
|
if tester.match(line.lower()):
|
||||||
if tester2.match(line):
|
if tester2.match(line.lower()):
|
||||||
return 'distanceplot'
|
return 'distanceplot'
|
||||||
if tester3.match(line):
|
if tester3.match(line.lower()):
|
||||||
return 'timeplot'
|
return 'timeplot'
|
||||||
if tester3.match(line):
|
if tester3.match(line.lower()):
|
||||||
return 'pieplot'
|
return 'pieplot'
|
||||||
|
|
||||||
def get_plotoptions_body2(uploadoptions,body):
|
def matchsync(line):
|
||||||
|
results = []
|
||||||
|
tester = '((sync)|(synchronization)|(export))'
|
||||||
|
tester2 = tester+'(.*)((c2)|(concept2)|(logbook))'
|
||||||
|
tester3 = tester+'(.*)((tp)|(trainingpeaks))'
|
||||||
|
tester4 = tester+'(.*)(strava)'
|
||||||
|
tester5 = tester+'(.*)((st)|(sporttracks))'
|
||||||
|
tester6 = tester+'(.*)((rk)|(runkeeper))'
|
||||||
|
tester7 = tester+'(.*)((mapmyfitness)|(underarmour)|(ua))'
|
||||||
|
|
||||||
|
tester = re.compile(tester)
|
||||||
|
|
||||||
|
if tester.match(line.lower()):
|
||||||
|
testers = [
|
||||||
|
('upload_to_C2',re.compile(tester2)),
|
||||||
|
('upload_totp',re.compile(tester3)),
|
||||||
|
('upload_to_Strava',re.compile(tester4)),
|
||||||
|
('upload_to_SportTracks',re.compile(tester5)),
|
||||||
|
('upload_to_RunKeeper',re.compile(tester6)),
|
||||||
|
('upload_to_MapMyFitness',re.compile(tester7)),
|
||||||
|
]
|
||||||
|
for t in testers:
|
||||||
|
if t[1].match(line.lower()):
|
||||||
|
results.append(t[0])
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def getprivateoptions_body2(uploadoptions,body):
|
||||||
|
tester = re.compile('^(priva)')
|
||||||
|
for line in body.splitlines():
|
||||||
|
if tester.match(line.lower()):
|
||||||
|
v = True
|
||||||
|
negs = ['false','False','None','no']
|
||||||
|
for neg in negs:
|
||||||
|
tstr = re.compile('^(.*)'+neg)
|
||||||
|
|
||||||
|
if tstr.match(line.lower()):
|
||||||
|
v = False
|
||||||
|
|
||||||
|
uploadoptions['makeprivate'] = v
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def getplotoptions_body2(uploadoptions,body):
|
||||||
for line in body.splitlines():
|
for line in body.splitlines():
|
||||||
chart = matchchart(line)
|
chart = matchchart(line)
|
||||||
if chart:
|
if chart:
|
||||||
uploadoptions['make_plot'] = True
|
uploadoptions['make_plot'] = True
|
||||||
uploadoptions['plottype'] = chart
|
uploadoptions['plottype'] = chart
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def getsyncoptions_body2(uploadoptions,body):
|
||||||
|
result = []
|
||||||
|
for line in body.splitlines():
|
||||||
|
result = result+matchsync(line)
|
||||||
|
|
||||||
|
result = list(set(result))
|
||||||
|
|
||||||
|
for r in result:
|
||||||
|
uploadoptions[r] = True
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
def getsyncoptions(uploadoptions,values):
|
def getsyncoptions(uploadoptions,values):
|
||||||
try:
|
try:
|
||||||
@@ -147,13 +203,18 @@ def upload_options(body):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
pm = exc.problem_mark
|
try:
|
||||||
strpm = str(pm)
|
uploadoptions = getplotoptions_body2(uploadoptions,body)
|
||||||
pbm = "Your email has an issue on line {} at position {}. The error is: ".format(
|
uploadoptions = getsyncoptions_body2(uploadoptions,body)
|
||||||
pm.line+1,
|
uploadoptions = getprivateoptions_body2(uploadoptions,body)
|
||||||
pm.column+1,
|
except IOError:
|
||||||
|
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
|
)+strpm
|
||||||
return {'error':pbm}
|
return {'error':pbm}
|
||||||
|
|
||||||
if uploadoptions == {}:
|
if uploadoptions == {}:
|
||||||
uploadoptions['message'] = 'No parsing issue. No valid commands detected'
|
uploadoptions['message'] = 'No parsing issue. No valid commands detected'
|
||||||
|
|||||||
Reference in New Issue
Block a user