I need to add the count statement to give urllib access the tuple of
urls. urllib needs to be given a different value each time in order to
check all the urls. This is the only way I could get the value (web) in
urllib to change each time. I tried indenting the count statement and
it runs without error but still only makes one pass. <br>
<br>
Thanks<br clear="all"><br>
Message: 1<br>
Date: Sun, 20 Nov 2005 22:26:10 -0500<br>
From: Kent Johnson <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:kent37@tds.net">kent37@tds.net</a>><br>
Subject: Re: [Tutor] Website monitoring program.<br>
Cc: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:tutor@python.org">tutor@python.org</a><br>
Message-ID: <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:43813E52.5010708@tds.net">43813E52.5010708@tds.net</a>><br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
Adisegna wrote:<br>
> How do I get the counting loop to come back around? It makes one pass<br>
> fine. How do I get it to come back up and go through again?<br>
<br>
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,<br>
<br>
>>> u = ['a', 'b', 'c']<br>
>>> for letter in u:<br>
... print letter<br>
...<br>
a<br>
b<br>
c<br>
<br>
So instead of<br>
count = 0<br>
for i in urls:<br>
web = urls[count]<br>
<br>
you can write simply<br>
for web in urls:<br>
<br>
See the Python tutorial for more examples of for loops:<br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://docs.python.org/tut/node6.html#SECTION006200000000000000000" target="_blank">http://docs.python.org/tut/node6.html#SECTION006200000000000000000</a><br>
<br>
Kent<br>
<br>
><br>
> Thanks<br>
><br>
> ------------------------------
<div id="mb_0">-------------------------<br>> import urllib, smtplib<br>><br>> urls = ("<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website0.net/imalive.asp" target="_blank">http://website0.net/imalive.asp
</a>",<br>> "<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website1.net/imalive.asp" target="_blank">http://website1.net/imalive.asp</a>",<br>> "<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website2.net/imalive.asp" target="_blank">
http://website2.net/imalive.asp</a>",<br>> "<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website3.net/imalive.asp" target="_blank">http://website3.net/imalive.asp</a>",
<br>> "<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website4.net/imalive.asp" target="_blank">http://website4.net/imalive.asp</a>"<br>> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website4.net/imalive.asp%22" target="_blank">
http://website4.net/imalive.asp%22</a>>,)<br>><br>> count = 0<br>> for i in urls:<br>> web = urls[count]<br>><br>> for site in urllib.urlopen(web):<br>><br>> good = "400 Bad Request"
<br>> bad = "Invalid Hostname"<br>> smtpserver = '<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.authentium.com/" target="_blank">mail.authentium.com</a> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.authentium.com/" target="_blank">
http://mail.authentium.com</a>>'<br>> RECIPIENTS = ['<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:my@address.com">my@address.com</a> <mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:my@address.com">
my@address.com</a>>']<br>> SENDER = '<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:website-Verification@address.com">website-Verification@address.com</a><br>> <mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:website-Verification@address.com">
website-Verification@address.com</a>>'<br>> mssg = site<br>><br>> if good in site:<br>> print "OK"<br>> text_file = open("test.log", "a")
<br>> text_file.writelines('sometext : ')<br>> text_file.writelines(site)<br>> text_file.writelines("\n")<br>> text_file.close()<br>><br>> elif bad in site:
<br>> print "NOT OK"<br>> text_file = open("test.log", "a")<br>> text_file.writelines('metro-ams : ')<br>> text_file.writelines(site)
<br>> text_file.writelines("\n")<br>> text_file.close()<br>> session = smtplib.SMTP(smtpserver)<br>> smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
<br>> if smtpresult:<br>> errstr = ""<br>> for recip in smtpresult.keys():<br>>
errstr = """Could not delivery mail to: %s<br>><br>> Server said: %s<br>> %s<br>><br>> %s""" % (recip, smtpresult[recip][0],
<br>> smtpresult[recip][1], errstr)<br>> raise smtplib.SMTPException, errstr<br>><br>><br>> else:<br>> text_file = open("test.log", "a")<br>
> text_file.writelines('Another type of error occurred : ')<br>> text_file.writelines(site)<br>> text_file.writelines("\n")<br>> text_file.close()
<br>> print web<br>> count +=1<br>> print count</div>
<br>-- <br>Arthur DiSegna<br>Network Operations Center<br>Authentium, Inc.