FAQ
I apologize for my newbiness but I'm banging my head making this work :
(
What change must I made for the tag enforcement being reflected to the
'mail' file? Am I using the WritableObject class correctly?
(I'm getting a blank 'mail' file after running the .py script)
How can I see the output run in debug mode like in perl?

#!/usr/bin/env python

import sys, os
import subprocess
import re
import datetime

# simple class with write method to redirect print output to a file
class WritableObject:
def __init__(self):
self.content = []
def write(self, string):
self.content.append(string)

x=datetime.date.today()
yyyy, dd = x.year, x.day

mail = WritableObject()
print >>mail, "To: %s" % (mail1)
print >>mail, "Subject: %s day %s " % (yyyy, dd)
print >>mail, "Content-Type: text/html; charset=\"us-ascii\""

subprocess.call("php $HOME/report.php > temp.txt", shell=True)
body = subprocess.call("cat $HOME/.txt", shell=True)

print >>mail, ""
print >>mail, "<html>"
print >>mail, "<body>"

#copies common header in the Problem html to the OK one
subprocess.call("cp $HOME/mail $HOME/OK.html", shell=True)

input_file = open('mail', 'r+')
lines = input_file.readlines()
input_file.close()
output_file = open("mail", "w+")

for line in lines:
if line.startswith('<p>'):
line = '<p>' + line.rstrip('\n') + '</p>' + '\n'
output_file.write(line)

if not body:
print >>mail, '''</p> <b>[No problems detected ].<b /> All monitored
metrics
<p><font size=\"4\">
<font color=\"darkgreen\">
<b>OK<b>
</p>
</font>
</body>
</html>'''
else:
print >>mail, '''
<table border=\"1\"> <tr>
<th> Table</th>
<th> Table2</th>
<th> Table3</th>
</tr>
</table>
%s
</body>
</html>''' % (body)

subprocess.call("sendmail me at my.mail < mail", shell=True)
output_file.close()

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 11 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedDec 9, '09 at 2:59p
activeDec 11, '09 at 3:22p
posts11
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase