[Tutor] Fwd: Website monitoring program.

Adisegna adisegna at gmail.com
Tue Nov 22 05:00:41 CET 2005


This worked for me..... Thanks!

------------------------------------------
for web in urls:

for site in urllib.urlopen(web):

-----------------------------------------------

You have to indent the statement 'count += 1' so it is part of the loop. But
you misunderstand the for loop - the count variable is not needed at all.
Your variable 'i' will receive each element of urls, one each time through
the loop. For a simpler example,

>>> u = ['a', 'b', 'c']
>>> for letter in u:
... print letter
...
a
b
c

So instead of
count = 0
for i in urls:
web = urls[count]

you can write simply
for web in urls:

See the Python tutorial for more examples of for loops:
http://docs.python.org/tut/node6.html#SECTION006200000000000000000

Kent

>
> Thanks
>
> ------------------------------ -------------------------
> 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%22>,)
>
> count = 0
> for i in urls:
> web = urls[count]
>
> for site in urllib.urlopen(web):
>
> good = "400 Bad Request"
> bad = "Invalid Hostname"
> smtpserver = 'mail.authentium.com <http://mail.authentium.com/> <http://mail.authentium.com
>'
> RECIPIENTS = ['my at address.com <mailto: my at address.com>']
> SENDER = 'website-Verification at address.com
> <mailto: website-Verification at address.com>'
> 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()
> print web
> count +=1
> print count

--
Arthur DiSegna
Network Operations Center
Authentium, Inc.

--
Arthur DiSegna
Network Operations Center
Authentium, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051121/6d1dc621/attachment-0001.htm


More information about the Tutor mailing list