Hi all,
I have a utility that invokes webchecker on a number of different websites,
given by a list, then mails the results to another list. I'm trying to trim
off the last line in the results file (per invocation on a site), that
usually says:
Use ``C:\Python22\Tools\webchecker\webchecker.py -R'' to restart.
The trick of it is I got it to work accidentally! But no longer ...
I fiddled with various combinations of a, a+, r, r+, w, w+ for open modes,
but I get either:
Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python22\Tools\webchecker\webnanny3.py", line 30, in ?
del lines[-1]
IndexError: list assignment index out of range
Or:
Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python22\Tools\webchecker\webnanny3.py", line 29, in ?
lines = fp.readlines()
IOError: [Errno 9] Bad file descriptor
Yet, the del lines[-1] works from the Interactive Window just fine.
Here's my code:
# Need this to run console commands
import os
# Need this to send email
import smtplib
# Need this to process email
from email.MIMEText import MIMEText
# Need this for time
from time import strftime
websites = ("http://hsa.ucdavis.edu", "http://ucdra.ucdavis.edu")
outfile = "results.txt"
recipients = ("[EMAIL PROTECTED]", "[EMAIL PROTECTED]")
# Open the file
fp = open(outfile,'w')
fp.write('Start of check')
fp.close()
# loop through websites
for site in websites:
# Write headers for each site
fp = open(outfile,'a')
fp.write('\n' + site + '\n')
fp.close()
# Run the webchecker script and write results to file
os.system("webchecker.py -q %s >> " %site + outfile )
# Trim off last line
fp = open(outfile, 'r+')
lines = fp.readlines()
del lines[-1]
fp.close()
# Get local time
runtime = strftime('%a %d %b %Y %H:%M:%S')
# Create message
fp = open(outfile,'r')
msg = MIMEText(fp.read())
fp.close()
# Loop through recipients
for you in recipients:
me = "Webnanny"
msg['Subject'] = 'Sites link check %s' % runtime
msg['From'] = me
msg['To']= you
server = smtplib.SMTP('hrrm.ucdavis.edu')
server.set_debuglevel(1)
#server.connect()
server.sendmail(me, you, msg.as_string())
server.quit()
***************************
* Adam Getchell [EMAIL PROTECTED]
* System Architect/Programmer (530) 752-1584
* Human Resources Information Systems http://www.hr.ucdavis.edu/
***************************
"Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython