Complete and tested email processing
Processed successfully individual files, zip files, unrecognized files, zips containing unrecognized files
This commit is contained in:
@@ -11,6 +11,7 @@ from time import strftime
|
||||
from django.core.management.base import BaseCommand
|
||||
from django_mailbox.models import Message, MessageAttachment
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
|
||||
from rowers.models import Workout, Rower
|
||||
|
||||
@@ -26,6 +27,9 @@ sys.path.append('$path_to_root_of_project$/$project_name$')
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
|
||||
|
||||
if not getattr(__builtins__, "WindowsError", None):
|
||||
class WindowsError(OSError): pass
|
||||
|
||||
def rdata(file_obj, rower=rrower()):
|
||||
""" Read rowing data file and return 0 if file doesn't exist"""
|
||||
try:
|
||||
@@ -35,15 +39,20 @@ def rdata(file_obj, rower=rrower()):
|
||||
|
||||
return result
|
||||
|
||||
def processattachment(rower, filename, title, uploadoptions):
|
||||
def processattachment(rower, fileobj, title, uploadoptions):
|
||||
try:
|
||||
filename = fileobj.name
|
||||
except AttributeError:
|
||||
filename = fileobj[6:]
|
||||
|
||||
workoutid = [
|
||||
make_new_workout_from_email(rower, filename[6:], title)
|
||||
make_new_workout_from_email(rower, filename, title)
|
||||
]
|
||||
if workoutid:
|
||||
link = 'https://rowsandall.com'+reverse(
|
||||
if workoutid[0]:
|
||||
link = settings.SITE_URL+reverse(
|
||||
rower.defaultlandingpage,
|
||||
kwargs = {
|
||||
'id':workoutid,
|
||||
'id':workoutid[0],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -62,23 +71,23 @@ def processattachment(rower, filename, title, uploadoptions):
|
||||
plottype, title,
|
||||
imagename=imagename
|
||||
)
|
||||
try:
|
||||
if workoutid:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
time.sleep(10)
|
||||
except:
|
||||
try:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
time.sleep(10)
|
||||
except:
|
||||
try:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
except:
|
||||
pass
|
||||
pass
|
||||
|
||||
return workoutid
|
||||
|
||||
@@ -119,6 +128,12 @@ class Command(BaseCommand):
|
||||
attachment.delete()
|
||||
except IOError:
|
||||
pass
|
||||
except WindowsError:
|
||||
time.sleep(2)
|
||||
try:
|
||||
attachment.delete()
|
||||
except WindowsError:
|
||||
pass
|
||||
|
||||
if message.attachments.exists() is False:
|
||||
# no attachments, so can be deleted
|
||||
|
||||
Reference in New Issue
Block a user