Ah, this kind of programme would be so much simpler if Last-Modified and
ETag were commonly used.... *sigh*. Unfortunately, advertising kinda killed
it...

I recommend www.watchthispage.com if you just need a quick update without
killing your own bandwidth.

Regards,

Liam Clarke-Hutchinson


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Kent Johnson
Sent: Monday, 21 November 2005 10:25 a.m.
Cc: tutor@python.org
Subject: Re: [Tutor] Website monitoring program.


Adisegna wrote:
> 
> I guess I should keep the same subject line (above) from now on since 
> my
> last few posts (urllib, smtplib) are about the same program. 

My preference is to start a new subject for each new question.
> 
> My question is how to use a loop to go through a tuple of URLs. Please
> feel free to suggest an easier way to do the same thing.
> 
> Here is my rudimentary program so far.
> 
> -------------------------------------------------------
> import urllib, smtplib
> 
> urls = ("http://website0.net/imalive.asp";,
>           "http://website1.net/imalive.asp";,
>           "http://website2.net/imalive.asp";,
>           "http://website3.net/imalive.asp";,
>           "http://website4.net/imalive.asp";
> <http://website4.net/imalive.asp";>,)
>          
> # I added these just to make the loop work and be more readable
> 
> qa = urls[0]
> n4k = urls[1]
> metro = urls[4]
> 
> for i in urls:   # <-- this obviously doens't work because I have to 
> specify a value "metro" below
> 
>     for site in urllib.urlopen(metro):  #<----- What can I use here to
> loop through the 'urls' tupple

I'm not sure I understand but I think what you want is

for url in urls:  # url will take on each value from urls
  site = urllib.urlopen(url).read()  # site will have the entire text from
the page you opened

You might also be interested in EDDIE which seems to support building this
kind of monitoring app fairly easily. http://eddie-tool.net/doc/manual.html

Kent

> 
>         good = "400 Bad Request"
>         bad = "Invalid Hostname"
>         smtpserver = 'mail.authentium.com <http://mail.authentium.com>'
>         RECIPIENTS = ['[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>']
>         SENDER = '[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>'
>         mssg = site
> 
>         if good in site:
>             print "OK"
>             text_file = open("test.log", "a")
>             text_file.writelines('sometext : ')
>             text_file.writelines(site)
>             text_file.writelines("\n")
>             text_file.close()
> 
>         elif bad in site:
>               print "NOT OK"
>               text_file = open("test.log", "a")
>               text_file.writelines('metro-ams : ')
>               text_file.writelines(site)
>               text_file.writelines("\n")
>               text_file.close()
>               session = smtplib.SMTP(smtpserver)
>               smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
>               if smtpresult:
>                         errstr = ""
>                         for recip in smtpresult.keys():
>                             errstr = """Could not delivery mail to: %s
> 
>                     Server said: %s
>                     %s
> 
>                     %s""" % (recip, smtpresult[recip][0],
> smtpresult[recip][1], errstr)
>                         raise smtplib.SMTPException, errstr
> 
>    
>         else:
>               text_file = open("test.log", "a")
>               text_file.writelines('Another type of error occurred : ')
>               text_file.writelines(site)
>               text_file.writelines("\n")
>               text_file.close()
>                
> ----------------------------------------------------------------------
> -------------
> 
> Thanks
> 
> 
> ----------------------------------------------------------------------
> --
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor

-- 
http://www.kentsjohnson.com

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to