In honor of PyCon (Python conference in downtown Atlanta) this weekend, I've decided to dedicate this post to a very valuable Python capability that can be extremely useful when running daily, behind-the-scenes scripts or scripts with lengthy processing times.
If there is a script that you run daily for some process such as an overnight synchronization, or an overnight cache, it can be a hassle checking the script's log file every morning to make sure it ran successfully. Or if there is a script you are running on an extremely large dataset with hundreds of thousands, or even millions of features, it would be nice to receive an email when the script completed that contained a subject providing information on whether the script completed successfully or stopped running due to some error, and in the message body see the error that caused the script to fail.
This can be done very easily with Python. I have uploaded a script to the Geospatial Database called PyEmail.py and it can be downloaded by right clicking on the link below and selecting "Save Target as...".
PyEmail.py
The uploaded script is written to work so that an email is generated once the script finishes running. If the script runs successfully, the email's subject displays "Script Completed Successfully!" and the message body is left blank. However, if the script fails, the subject displays "Script Failed", a log file with error messages is attached to the email, and the message body of the email notifies the user to check the attached log files for errors. The script can be easily modified to meet your own personal needs - maybe you only want to receive an email if the script fails, maybe you want the error messages to just print to the message body instead of having a log file, etc. All of these things are pretty simple changes within the script.
What the script requires from you:
1) Your own code which you will paste into the PyEmail script.
2) The path to your log file (if you are using a log file to catch error messages).
3) The email address(es) of the recipient(s).
4) The name and email address of the sender.
5) IP or name of the mail server used to send the email.
6) SMTP user name and password (if you are using SMTP authentification).
Sunday, February 21, 2010
Using Python to Generate Status Emails for Lengthy Geoprocessing Tasks
Labels:
email,
free,
geoprocessing,
geospatial,
geospatial database,
gis,
python,
tools
Subscribe to:
Post Comments (Atom)
2 comments: