I have an email that comes in everyday and the format of the email is always the same except some of the data is different. I wrote a VBA Macro that exports the email to a text file. Now that it is a text file I want to parse the data so that I get only the new information.
The format of email is like this
> Irrelevant data
> Irrelevant data
> Type: YUK
> Status: OPEN
> Date: 6/22/2015
> Description: ----
>
> Description blah blah blah
> Thank you
I want to capture the relevant data. For example, in this case i would like to only capture YUK, OPEN, 6/22/2015 and the Description blah blah blah. I tried using the csv module to go line by line and print out the lines but i cant seem to find a way to parse that information.
This is what I have so far. it only prints out the lines though.
import os
import glob
import csv
path = "emailtxt/"
glob = max(glob.iglob(path + '*.txt'), key=os.path.getctime)#most recent file located in the emailtxt
newestFile = os.path.basename(glob)#removes the emailtxt\ from its name
f = open(path+newestFile)
read = csv.reader(f)
for row in read:
print row
f.close()
How would I parse through the text file?
csvformat to go forcsvmodule?