email processing working on develop
This commit is contained in:
@@ -37,8 +37,10 @@ def send_confirm(u,name,link,options):
|
|||||||
message += "Your workout has been added to Rowsandall.com.\n"
|
message += "Your workout has been added to Rowsandall.com.\n"
|
||||||
message += "Link to workout: "+link+"\n\n"
|
message += "Link to workout: "+link+"\n\n"
|
||||||
message += "Best Regards, the Rowsandall Team"
|
message += "Best Regards, the Rowsandall Team"
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
message += "\n\n"+options
|
message += "\n\n"+str(options)
|
||||||
|
|
||||||
|
|
||||||
email = EmailMessage(subject,message,
|
email = EmailMessage(subject,message,
|
||||||
'Rowsandall <info@rowsandall.com>',
|
'Rowsandall <info@rowsandall.com>',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
#from rowers.mailprocessing import processattachments
|
#from rowers.mailprocessing import processattachments
|
||||||
import time
|
import time
|
||||||
|
from time import strftime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rowers.tasks import handle_sendemail_unrecognized
|
from rowers.tasks import handle_sendemail_unrecognized
|
||||||
from django_mailbox.models import Mailbox,Message,MessageAttachment
|
from django_mailbox.models import Mailbox,Message,MessageAttachment
|
||||||
@@ -51,7 +52,7 @@ class Command(BaseCommand):
|
|||||||
extension = a.document.name[-3:].lower()
|
extension = a.document.name[-3:].lower()
|
||||||
donotdelete = 0
|
donotdelete = 0
|
||||||
m = Message.objects.get(id=a.message_id)
|
m = Message.objects.get(id=a.message_id)
|
||||||
body = m.text
|
body = "\n".join(m.text.splitlines())
|
||||||
uploadoptions = uploads.upload_options(body)
|
uploadoptions = uploads.upload_options(body)
|
||||||
from_address = m.from_address[0].lower()
|
from_address = m.from_address[0].lower()
|
||||||
name = m.subject
|
name = m.subject
|
||||||
@@ -73,15 +74,19 @@ class Command(BaseCommand):
|
|||||||
res += wid
|
res += wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
if uploadoptions and not 'error' in uploadoptions:
|
if uploadoptions and not 'error' in uploadoptions:
|
||||||
w = Workout.objects.get(wid[0])
|
w = Workout.objects.get(id=wid[0])
|
||||||
r = w.user
|
r = w.user
|
||||||
uploads.do_sync(w,uploadoptions)
|
uploads.do_sync(w,uploadoptions)
|
||||||
uploads.make_private(w,uploadoptions)
|
uploads.make_private(w,uploadoptions)
|
||||||
if 'make_plot' in uploadoptions:
|
if 'make_plot' in uploadoptions:
|
||||||
plottype = uploadoptions['plottype']
|
plottype = uploadoptions['plottype']
|
||||||
res = uploads.make_plot(r,w,f2[6:],
|
f1 = w.csvfilename[6:-4]
|
||||||
w.csvfilename,
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
plottype,title)
|
imagename = f1+timestr+'.png'
|
||||||
|
resu = uploads.make_plot(r,w,f1,
|
||||||
|
w.csvfilename,
|
||||||
|
plottype,name,
|
||||||
|
imagename=imagename)
|
||||||
try:
|
try:
|
||||||
if wid != 1:
|
if wid != 1:
|
||||||
dd = send_confirm(rr.user,title,link,
|
dd = send_confirm(rr.user,title,link,
|
||||||
@@ -107,16 +112,19 @@ class Command(BaseCommand):
|
|||||||
res += wid
|
res += wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
if uploadoptions:
|
if uploadoptions:
|
||||||
w = Workout.objects.get(wid[0])
|
w = Workout.objects.get(id=wid[0])
|
||||||
r = w.user
|
r = w.user
|
||||||
uploads.do_sync(w,uploadoptions)
|
uploads.do_sync(w,uploadoptions)
|
||||||
uploads.make_private(w,uploadoptions)
|
uploads.make_private(w,uploadoptions)
|
||||||
if 'make_plot' in uploadoptions:
|
if 'make_plot' in uploadoptions:
|
||||||
plottype = uploadoptions['plottype']
|
plottype = uploadoptions['plottype']
|
||||||
res = uploads.make_plot(r,w,a.document,
|
f1 = w.csvfilename[6:-4]
|
||||||
w.csvfilename,
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
plottype,name)
|
imagename = f1+timestr+'.png'
|
||||||
|
resu = uploads.make_plot(r,w,f1,
|
||||||
|
w.csvfilename,
|
||||||
|
plottype,name,
|
||||||
|
imagename=imagename)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# replace with code to process error
|
# replace with code to process error
|
||||||
@@ -131,7 +139,7 @@ class Command(BaseCommand):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# remove attachment
|
# remove attachment
|
||||||
if donotdelete == 0:
|
if donotdelete == 0:
|
||||||
a.delete()
|
a.delete()
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,13 @@ from rowers.utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
def cleanbody(body):
|
def cleanbody(body):
|
||||||
p = re.compile('.*---\n([\s\S]*)...')
|
regex = r".*---\n([\s\S]*?)\.\.\..*"
|
||||||
m = p.match(body)
|
matches = re.finditer(regex,body)
|
||||||
if m != None:
|
|
||||||
body = m.group(1)
|
for m in matches:
|
||||||
|
|
||||||
|
if m != None:
|
||||||
|
body = m.group(0)
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
@@ -191,7 +194,7 @@ def do_sync(w,options):
|
|||||||
if 'upload_to_C2' in options and options['upload_to_C2']:
|
if 'upload_to_C2' in options and options['upload_to_C2']:
|
||||||
try:
|
try:
|
||||||
message,id = c2stuff.workout_c2_upload(w.user.user,w)
|
message,id = c2stuff.workout_c2_upload(w.user.user,w)
|
||||||
except C2NoTokenError:
|
except c2stuff.C2NoTokenError:
|
||||||
id = 0
|
id = 0
|
||||||
message = "Something went wrong with the Concept2 sync"
|
message = "Something went wrong with the Concept2 sync"
|
||||||
|
|
||||||
@@ -200,7 +203,7 @@ def do_sync(w,options):
|
|||||||
message,id = stravastuff.workout_strava_upload(
|
message,id = stravastuff.workout_strava_upload(
|
||||||
w.user.user,w
|
w.user.user,w
|
||||||
)
|
)
|
||||||
except StravaNoTokenError:
|
except stravastuff.StravaNoTokenError:
|
||||||
id = 0
|
id = 0
|
||||||
message = "Please connect to Strava first"
|
message = "Please connect to Strava first"
|
||||||
|
|
||||||
@@ -210,7 +213,7 @@ def do_sync(w,options):
|
|||||||
message,id = sporttracksstuff.workout_sporttracks_upload(
|
message,id = sporttracksstuff.workout_sporttracks_upload(
|
||||||
w.user.user,w
|
w.user.user,w
|
||||||
)
|
)
|
||||||
except SportTracksNoTokenError:
|
except sporttracksstuff.SportTracksNoTokenError:
|
||||||
message = "Please connect to SportTracks first"
|
message = "Please connect to SportTracks first"
|
||||||
id = 0
|
id = 0
|
||||||
|
|
||||||
@@ -220,7 +223,7 @@ def do_sync(w,options):
|
|||||||
message,id = runkeeperstuff.workout_runkeeper_upload(
|
message,id = runkeeperstuff.workout_runkeeper_upload(
|
||||||
w.user.user,w
|
w.user.user,w
|
||||||
)
|
)
|
||||||
except RunKeeperNoTokenError:
|
except runkeeperstuff.RunKeeperNoTokenError:
|
||||||
message = "Please connect to Runkeeper first"
|
message = "Please connect to Runkeeper first"
|
||||||
id = 0
|
id = 0
|
||||||
|
|
||||||
@@ -229,7 +232,7 @@ def do_sync(w,options):
|
|||||||
message,id = underarmourstuff.workout_ua_upload(
|
message,id = underarmourstuff.workout_ua_upload(
|
||||||
w.user.user,w
|
w.user.user,w
|
||||||
)
|
)
|
||||||
except UnderArmourNoTokenError:
|
except underarmourstuff.UnderArmourNoTokenError:
|
||||||
message = "Please connect to MapMyFitness first"
|
message = "Please connect to MapMyFitness first"
|
||||||
id = 0
|
id = 0
|
||||||
|
|
||||||
@@ -239,7 +242,7 @@ def do_sync(w,options):
|
|||||||
message,id = tpstuff.workout_tp_upload(
|
message,id = tpstuff.workout_tp_upload(
|
||||||
w.user.user,w
|
w.user.user,w
|
||||||
)
|
)
|
||||||
except TPNoTokenError:
|
except tpstuff.TPNoTokenError:
|
||||||
message = "Please connect to TrainingPeaks first"
|
message = "Please connect to TrainingPeaks first"
|
||||||
id = 0
|
id = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user