Straightforward title, straightforward goal, ugly and roundabout (but free!) method of achieving it.
For some time now, I’ve had this goal: download my gmail data, analyze it, and visualize it.
The last time I tried this, I glossed over the whole getting your gmail data into Excel part. This is because I wasn’t able to do all of it myself–Jim had to take my ugly mbox data and make it Excel-readable.
But now, thanks to the basic python skills acquired in my data science class, I can do everything myself! Kinda. The code in part 3 will probably make a real programmer scream, but for the most part, it works–though it’s not fond of commas in subject lines. And if you, like me, are not a programmer–don’t worry! You can still run the code, using my trusty copy/paste/pray methodology.
Alors, here goes:
Step 1: From Gmail to Apple Mail
You have Apple mail, right? You can also do this with Outlook, and probably other desktop clients.
1) In your Gmail settings, go to the “Forwarding and POP/IMAP tab” and make sure POP is enabled.
2) Now, add your Gmail account to your desktop client o’choice. If it’s already there, add it again–you’re going to be removing this one.
Important: Do not check the “remove copy from server after retrieving a message” box!
Step 2: From Apple Mail to mbox
This part is easy. Just select your mailbox in the desktop client, and go to Mailbox->Export Mailbox, and choose a destination folder.
Step 3: From mbox to csv
If you try to save your pristine mbox file as a csv, you will get a one column csv. Don’t do that. Instead, use these python scripts (also up on github).
The first script opens a blank csv file, and fills it with the subject, from, and date lines for each message in your mbox. I called it mbox_parser.py.
import mailbox import csv writer = csv.writer(open("clean_mail.csv", "wb")) for message in mailbox.mbox('your_mbox_name'): writer.writerow([message['subject'], message['from'], message['date']])
If you don’t know what python is, you can still run this script. Here’s how:
1) copy the above code to a plain text file, and save it as mbox_parser.py. Save it to the same folder you saved your mbox file to.
2) open your terminal (spotlight–>terminal)
3) type cd Users/your_account_name/directory_where_you_saved_your_mbox,
4) type python mbox_parser.py
5) Voila! In your directory, you should see a new file, cleaner.csv.
You’ll notice that the ‘date’ column is a long, jam-packed date string. It’ll be much easier to Continue reading Carpe Datum: How to Export Your GMail to Excel