|
|
@@ -25,6 +25,8 @@ import datetime
|
|
|
import matplotlib.pyplot as plt
|
|
|
import matplotlib.dates as mdates
|
|
|
import argparse
|
|
|
+import re
|
|
|
+import cubehelix
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
@@ -33,6 +35,10 @@ parser.add_argument('--plotfile', '-p', default=False, action='store',
|
|
|
help='Name of output plotting file.')
|
|
|
parser.add_argument('--title', '-t', default='Email Send Times',
|
|
|
action='store', help='Plot title.')
|
|
|
+parser.add_argument('--sendercolors', '-s', default=False, action='store',
|
|
|
+ help='Comma separated list of search strings for the \
|
|
|
+ sender field. Each will be displayed with a \
|
|
|
+ different color.')
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
plt.figure()
|
|
|
@@ -42,7 +48,18 @@ plt.xlabel('Date')
|
|
|
plt.minorticks_on()
|
|
|
plt.title(args.title)
|
|
|
a = mailbox.mbox(args.mbox)
|
|
|
+
|
|
|
+if args.sendercolors:
|
|
|
+ slist = args.sendercolors.split(',')
|
|
|
+ nsend = len(slist)
|
|
|
+ scolor = cubehelix.cmap(startHue=240, endHue=-300,
|
|
|
+ minSat=1, maxSat=2.5,
|
|
|
+ minLight=.3, maxLight=.8,
|
|
|
+ gamma=.9)
|
|
|
+
|
|
|
for msg in a:
|
|
|
+ cid = None
|
|
|
+ label = None
|
|
|
if msg['date'] is not None:
|
|
|
try:
|
|
|
z = datetime.datetime.strptime(msg['date'], '%a, %d %b %Y %H:%M:%S %z')
|
|
|
@@ -52,12 +69,25 @@ for msg in a:
|
|
|
except ValueError:
|
|
|
print("Skipping message from " + msg['date'])
|
|
|
continue
|
|
|
+ if args.sendercolors:
|
|
|
+ for search in enumerate(slist):
|
|
|
+ if re.search(search[1], msg['From'], re.IGNORECASE):
|
|
|
+ cid, label = search
|
|
|
+ break
|
|
|
+ if cid is None:
|
|
|
+ cid = nsend+1
|
|
|
+ label = 'unknown'
|
|
|
plt.plot_date(z.date(),
|
|
|
z.hour + z.minute/60.,
|
|
|
- fmt='r.',
|
|
|
+ color=scolor(cid / (nsend + 1)),
|
|
|
+ ls='.',
|
|
|
# tz=z.tzname(),
|
|
|
+ label=label,
|
|
|
xdate=True)
|
|
|
|
|
|
+if args.sendercolors:
|
|
|
+ plt.legend()
|
|
|
+
|
|
|
if args.plotfile:
|
|
|
plt.savefig(args.plotfile)
|
|
|
else:
|