Reputation: 5127
I am trying to do the following,but the data finally that gets feeded to outlook is messedup,please look at the pastie links below for input,output and the code
1.read data from an xml using minidom 2.and if there are hyperlinks ,am replacing with a regex to add ahref atribute 3.Outputting the data to outlook
INPUT/Output:-
http://pastie.org/5408694
My code:-
# Import package to access Outlook
import win32com.client
import re
import xml.dom.minidom as minidom
resultslis=[]
def getsanityresults(xmlfile):
dom = minidom.parse(xmlfile)
data=dom.getElementsByTagName('Sanity_Results')
textnode = data[0].childNodes[0]
testresults=textnode.data
for line in testresults.splitlines():
line = line.strip('\r,\n')
line = re.sub(r'(http://[^\s]+|//[^\s]+|\\\\[^\s]+)', r'<a href="\1">\1</a>', line)
print line
resultslis.append(line)
return resultslis
def main ():
file = open('results.xml','r')
sanityresults=getsanityresults(file)
print sanityresults
msg_body=("<HTML><head></head>"
"<body> <font face = \"Calibri\" <br>"
"<font face = \"Calibri\"%s<br><br>"
"</body></html>"
) % (sanityresults)
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.HTMLBody = msg_body
newMail.display()
if __name__ == '__main__':
main()
Upvotes: 0
Views: 557
Reputation: 5127
I am answering my own question.following change to subroutine worked
def getsanityresults(xmlfile):
testresult=[]
dom = minidom.parse(xmlfile)
data=dom.getElementsByTagName('Sanity_Results')
textnode = data[0].childNodes[0]
testresults=textnode.data
for line in testresults.splitlines():
line = line.strip('\r,\n')
line = re.sub(r'(http://[^\s]+|//[^\s]+|\\\\[^\s]+)', r'<a href="\1">\1</a>', line)
testresult.append(line)
return '<br>'.join(testresult)
Upvotes: 1