urlwatch modified for smtp with login

I came across urlwatch whilst looking for something to tell me if a web page had been updated.

http://thp.io/2008/urlwatch/

Its pure python, and easy for even a beginner like me to read and sus out once I’d worked out where the files were.

Your can install it with sudo pip install urlwatch – I needed to install the futures thing too – sudo pip install futures

It has the capability to send updates as email, but it did not support email to an authenticated SMTP server.  After a bit of digging I saw that email is handled by /usr/local/lib/python2.7/dist-packages/urlwatch/mailer.py

import smtplib
from email.mime.text import MIMEText

def send(smtp_server, from_email, to_email, subject, body):
msg = MIMEText(body, ‘plain’, ‘utf_8’)
msg[‘Subject’] = subject
msg[‘From’] = from_email
msg[‘To’] = to_email

s = smtplib.SMTP()
s.connect(smtp_server, 25)
s.sendmail(from_email, [to_email], msg.as_string())
s.quit()

I needed to edit the server port from 25 to a higher number correct for my service provider, and also add a line between the s.connect and the s.sendmail

s.login(‘username’, ‘password’)

edit the urls.txt file in your .urlwatch directory, then stick an entry in crontab for urlwatch -t to_email -s mailserver

and whenever it runs it will tell you if any of the web pages in your urls.txt have changed since it last run

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: