RWEL Homework – another approach – playing around with email and ngrams
I sometimes have crazy email interactions with my mother, and I decided to take her emails and write some ngrams with them – and see how they fare
When I was just starting out I figured out how to pull in the body text from emails from specific people (in the process I accidentally deleted 12,000 unread messages (it took about 20 minutes) but… I realize my gmail box needs some sorting
import sys import imaplib, re conn = imaplib.IMAP4_SSL("imap.gmail.com", 993) conn.login('gabriella.levine', 'qwewqwe1!') output = conn.select("INBOX") print "new messages", output unread=conn.search(None, 'UnSeen') print unread unreadCount = re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1) print "unread", unreadCount def get_emails_from_ruth(): ruth = conn.search(None, 'FROM', '"Ruth"') print "ruth", ruth #have to write a functioin that outputs ruth then run it in a nother function below ruthmsg #output ruth ruthmsg = conn.fetch('149', '(BODY.PEEK[TEXT])') print ruthmsg #msgdata = conn.fetch(num, "(BODY.PEEK[HEADER.FIELDS (FROM TO CC DATE SUBJECT MESSAGE-ID)] UID)")
This gave me each number of her emails in a list, as well as how many I had from her, as well as a large mass of text from one of her emails. Then I wrote it better so I got all of her emails, as a text, and only the body text of her email (so I split the text on “7BIT\r\n\r\nhi” and “\r\n\r\n–Boundary” which surrounded the body text of every email I extracted and printed out.
I wasn’t able to get all of her emails but here is some of what I output:
thought you might like to you can breathe a good time together: i thought you can babble on and on like the one who i\’ve been back in a good time didn\’t pass. we\’re together. what a good time together: in our lives in a good time didn\’t pass. have so much fun when we\’re together. we feel great depths for us.\r\n it\’s wonderful for us.\r\n these are SOOOOO different in our lives in touch with her last night. it\’s like my dinner with her last night. schook – the man she lives now can breathe a good time together: i knew all the man she married, and uncles and brother and have such a different world realistically and aunts and emotionally and intellectually, but we can babble on and i thought you when you when we\’re together. mom
hi gabby,, we feel great depths for each other and brother and aunts and have such a good time together: we have so much fun when we\’re together. i thought you might like the one who i\’ve been back in a relief afterwards, hopefully. it\’s like the same about me. noone in tons of relief afterwards, hopefully. it\’s like my dinner with her parents and have you can breathe a sigh of course, there\’s history: mom
So I have to clean it up a lot, and take out the line break symbols. But It is something I will work with. My first step is to get every email in the list (I was getting an error when I was trying to pass in all the emails from her, as opposed to a few at a time)