I'm new to Python and apologies if this is trivial for you.Some of email contain following line in email body:
Event demon log entry:
[27/12/2018 08:15:02] CAUAJM_I_40245 EVENT: ALARM ALARM: MAXRUNALARM JOB: p1_credit_qv_curve_snap MACHINE: p1prog06
With this code
#!/usr/bin/python
import email, imaplib, re
user = 'user@example.com'
pwd = 'pass'
conn = imaplib.IMAP4_SSL("outlook.office365.com")
conn.login(user,pwd)
conn.select("Inbox")
resp, items = conn.uid("search",None, 'All')
items = items[0].split()
for emailid in items:
resp, data = conn.uid("fetch",emailid, "(RFC822)")
if resp == 'OK':
email_body = data[0][1].decode('utf-8')
mail = email.message_from_string(email_body)
if mail["Subject"].find("PA1") > 0 or mail["Subject"].find("PA2") > 0:
match=re.findall(r'Event demon log entry.*\n.*\n.*', email_body , re.IGNORECASE)
print match
i'm getting:
[u'Event demon log entry:\r\n\r\n[27/12/2018 08:15:02] CAUAJM_I_40245 EVENT: ALARM ALARM: MAXRUNALARM JOB: p=\r', u'Event demon log entry:<br><br=\r\n>[27/12/2018 08:15:02] CAUAJM_I_40245 EVENT: ALARM ALARM: M=\r\nAXRUNALARM JOB: p1_credit_qv_curve_snap MACHINE: p1prog06<br><br>Attac=\r']
How to get rid of those HTML outputs ?
i need following output (if it's possible in one line):
Event demon log entry:[27/12/2018 08:15:02] CAUAJM_I_40245 EVENT: ALARM ALARM: MAXRUNALARM JOB: p1_credit_qv_curve_snap MACHINE: p1prog06