Emailing the attachment created with the Quick Screenshots Script(Python + PIL)

Mark Bratcher mbratcher at cclpcitrus.com
Fri Sep 28 11:56:18 EDT 2007


The quick screenshots script works great for the project I'm working on and
I'm trying to modify it to include emailing the JPG file it generates.  I
retrieved both scripts from the Python Archives.  The modified script is
pasted below and the errors below that.  My goal is to have the latest date
stamped file emailed to me.

 

If someone can see where I've gone wrong, it would be greatly appreciated.

 

"""

Simple script to capture your screen, save it named with today's date and
then

open it to allow editing and markup (circle problems, etc)

 

Created by Greg Pinero (gregpinero at gmail.com) Spring 2005

 

To run this you'll need:

>Python Imaging Library (PIL) -http://www.pythonware.com/products/pil/

>Python 2.3 or later - http://www.python.org

>Windows?

"""

import os

import sys

import time

import Image

import ImageGrab

#---------------------------------------------------------

#User Settings:

SaveDirectory=r'C:\Downloads\Python\Attachments'

ImageEditorPath=r'C:\WINDOWS\system32\mspaint.exe'

#Here is another example:

#ImageEditorPath=r'C:\Program Files\IrfanView\i_view32.exe'

#---------------------------------------------------------

 

img=ImageGrab.grab()

saveas=os.path.join(SaveDirectory,'ScreenShot_'+time.strftime('%Y_%m_%d%_%H_
%M_%S')+'.jpg')

img.save(saveas)

editorstring='"start"%s" "%s"'% (ImageEditorPath,saveas) #Just for Windows
right now?

#Notice the first leading " above? This is the bug in python that no one
will admit...

os.system(editorstring)

 

# Import smtplib for the actual sending function

import smtplib

 

# Here are the email package modules we'll need

from email.mime.image import MIMEImage

from email.mime.multipart import MIMEMultipart

 

COMMASPACE = ', '

 

# Create the container (outer) email message.

msg = MIMEMultipart()

msg['Subject'] = 'TEST'

# me == the sender's email address

# family = the list of all recipients' email addresses

msg['From'] = ("Mark Bratcher")

msg['To'] = COMMASPACE.join("Mark Bratcher")

msg.preamble = 'TEST'

 

# Assume we know that the image files are all in JPG format

for file in "c:\downloads\python\Attachments\*.jpg":

# Open the files in binary mode.  Let the MIMEImage class automatically

    # guess the specific image type.

    fp = open(file, 'rb')

    img = MIMEImage(fp.read())

    fp.close()

    msg.attach(img)

 

# Send the email via our own SMTP server.

s = smtplib.SMTP()

s.connect()

s.sendmail(me, family, msg.as_string())

s.close()

 

The errors I'm receiving in the Python Shell are:

 

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open('C:\Downloads\Python\Attachments\*.jpg', 'rb')

IOError: [Errno 2] No such file or directory:
'C:\\Downloads\\Python\\Attachments\\*.jpg'

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open('\Downloads\Python\Attachments\*.jpg', 'rb')

IOError: [Errno 2] No such file or directory:
'\\Downloads\\Python\\Attachments\\*.jpg'

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open('*.jpg', 'rb')

IOError: [Errno 2] No such file or directory: '*.jpg'

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 51, in <module>

    for file in jpgfiles:

NameError: name 'jpgfiles' is not defined

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open(file, 'rb')

IOError: [Errno 2] No such file or directory: 'c'

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open(file, 'rb')

IOError: [Errno 2] No such file or directory: 'c'

>>> 

Traceback (most recent call last):

  File "C:\Downloads\Python\screenshooter.pyw", line 54, in <module>

    fp = open(file, 'rb')

IOError: [Errno 2] No such file or directory: 'c'

 

 

Mark Bratcher

Consolidated Citrus, LP

4210-250 Metro, Parkway

Fort Myers, FL  33916

239-275-4060 ext 219

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070928/53a8367c/attachment.html>


More information about the Python-list mailing list