I'd just like to say Pythonista is an absolute life saver and I love using it. I've had an issue with Ole's email script that I've been using to upload dated image from gmail to flickr for an art project It worked fine prior to 1.5 but the portrait uploads now appear as landscape on flickr. I tried rotating the image in the code, but it had no effect. Any help gratefully received.
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email import encoders
import Image
import photos
from io import BytesIO
import datetime
today = datetime.datetime.now()
def get_attachment(img):
bytes = BytesIO()
img.save(bytes, format='JPEG')
msg = MIMEBase('image', 'jpeg')
msg.set_payload(bytes.getvalue())
encoders.encode_base64(msg)
msg.add_header('Content-Disposition', 'attachment',
filename='image.jpeg')
return msg
def main():
### CHANGE THESE VALUES:
to = '**********************@photos.flickr.com'
subject = today.strftime("#%j")
gmail_user = '*******************'
gmail_pwd = '*******************'
#Load a sample image, modify as needed:
image = photos.pick_image(show_albums=False)
print 'Connecting...'
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
print 'Preparing message...'
outer = MIMEMultipart()
outer['Subject'] = subject
outer['To'] = to
outer['From'] = gmail_user
outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
attachment = get_attachment(image)
outer.attach(attachment)
composed = outer.as_string()
print 'Sending...'
smtpserver.sendmail(gmail_user, to, composed)
smtpserver.close()
print 'Done.'
if __name__ == '__main__':
main()