Private
Public Access
1
0

works now - send workout to email message

This commit is contained in:
Sander Roosendaal
2018-06-05 22:18:58 +02:00
parent 278e99a38c
commit a277f71af3
2 changed files with 25 additions and 2 deletions

View File

@@ -47,6 +47,8 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
filename = fileobj.name filename = fileobj.name
except AttributeError: except AttributeError:
filename = fileobj[6:] filename = fileobj[6:]
if testing:
print 'Attribute Error', filename
# test if file exists and is not empty # test if file exists and is not empty
@@ -54,12 +56,20 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
with open('media/'+filename,'r') as fop: with open('media/'+filename,'r') as fop:
line = fop.readline() line = fop.readline()
except IOError: except IOError:
if testing:
print 'IOError',filename,'media/'+filename
return 0 return 0
if testing:
print 'Creating workout from email'
workoutid = [ workoutid = [
make_new_workout_from_email(rower, filename, title,testing=testing) make_new_workout_from_email(rower, filename, title,testing=testing)
] ]
if testing:
print 'Workout id = {workoutid}'.format(workoutid=workoutid)
if workoutid[0]: if workoutid[0]:
link = settings.SITE_URL+reverse( link = settings.SITE_URL+reverse(
rower.defaultlandingpage, rower.defaultlandingpage,
@@ -185,6 +195,9 @@ class Command(BaseCommand):
) )
else: else:
# move attachment and make workout # move attachment and make workout
if testing:
print name
print attachment.document
workoutid = processattachment( workoutid = processattachment(
rower, attachment.document, name, uploadoptions, rower, attachment.document, name, uploadoptions,
testing=testing testing=testing

View File

@@ -16,6 +16,7 @@ from math import sin,cos,atan2,sqrt
import os,sys import os,sys
import gzip import gzip
import base64 import base64
import yaml
# Django # Django
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
@@ -154,6 +155,14 @@ def get_polar_workouts(user):
if response.status_code == 201: if response.status_code == 201:
workoutsbox = Mailbox.objects.filter(name='workouts')[0] workoutsbox = Mailbox.objects.filter(name='workouts')[0]
uploadoptions = {
'makeprivate':False,
}
bodyyaml = yaml.safe_dump(
uploadoptions,
default_flow_style=False
)
transactionid = response.json()['transaction-id'] transactionid = response.json()['transaction-id']
url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}'.format( url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}'.format(
@@ -180,11 +189,12 @@ def get_polar_workouts(user):
msg = Message(mailbox=workoutsbox, msg = Message(mailbox=workoutsbox,
from_header=user.email, from_header=user.email,
subject = 'Import from Polar Flow') subject = 'Import from Polar Flow',
body=bodyyaml)
msg.save() msg.save()
a = MessageAttachment(message=msg,document=filename) a = MessageAttachment(message=msg,document=filename[6:])
a.save() a.save()
exercise_dict['filename'] = filename exercise_dict['filename'] = filename