Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2015 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a727902cb2d669623fce to your computer and use it in GitHub Desktop.
Save anonymous/a727902cb2d669623fce to your computer and use it in GitHub Desktop.
import os
from datetime import datetime
key = "Subject: New scikit-learn questions"
path = '/Users/[ username ]/Library/Mail/[ mailboxname ]/INBOX.imapmbox/Messages/'
fnames = [p for p in os.listdir(path) if p.endswith('.emlx')]
times = []
for i,fname in enumerate(fnames):
print i+1, "/", len(fnames)
with open(path+fname) as f: txt = f.read()
if key not in txt: continue
date = [line for line in txt.split('\n') if line.startswith('Date:')][0][6:-6]
date = datetime.strptime(date, "%a, %d %b %Y %H:%M:%S")
times.append(date)
times = sorted(times)
deltas = [(times[i+1]-times[i]).total_seconds() for i in range(len(times)-1)]
seconds_in_24h = 86400.
times2 = [(t.hour*3600 + t.minute*60 + t.second)/seconds_in_24h*24 for t in times]
import matplotlib.pyplot as plt
plt.plot(times2)
plt.ylabel('Hour of day recieved')
plt.xlabel('Newsletters sorted by date')
plt.savefig('./newsletters-times.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment