+#!/usr/bin/env python3
+
+import datetime
+import mailbox
+import numpy as np
+import pandas as pd
+
+# import caldav stuff
+import caldav
+from caldav.elements import dav, cdav
+
+nimbus_password = '7TS3L-xABPz-8PJwn-zxAz7-ZY2Y5'
+database_filename = "list_of_databases.csv"
+
+current_timestamp = datetime.datetime.now()
+data_original = pd.read_csv(database_filename)
+
+def get_flags_for_maildir (maildir_name):
+ mb_counts = { 'unread' : 0, 'flagged' : 0 }
+
+ mb = mailbox.Maildir(maildir_name)
+
+ for msg in mb:
+ flags = msg.get_flags()
+ if "S" not in flags:
+ mb_counts['unread'] += 1
+ if "F" in flags:
+ mb_counts['flagged'] += 1
+
+ return mb_counts
+
+def rows_from_mb_counts (source_string, mb_counts):
+ return pd.DataFrame({'time' : current_timestamp,
+ 'source' : source_string,
+ 'feature' : list(mb_counts.keys()),
+ 'count' : list(mb_counts.values())})
+
+data_email_personal = rows_from_mb_counts("default inbox",
+ get_flags_for_maildir("~/incoming/mail/default"))
+
+data_email_uw = rows_from_mb_counts("UW inbox",
+ get_flags_for_maildir("~/incoming/mail/uw-inbox"))
+
+# load calendar data
+caldav_client = caldav.DAVClient("https://mako:{pw}@nimbus.mako.cc/remote.php/dav/calendars/mako/personal/".format(pw=nimbus_password))
+cal = caldav_client.principal().calendars()[0]
+
+caldav_count = np.sum(["PERCENT-COMPLETE:100" not in c.data
+ for c in cal.todos(include_completed=True)])
+
+data_nextcloud = pd.DataFrame({'time' : [current_timestamp],
+ 'source' : ['nextcloud tasks'],
+ 'feature' : ['open'],
+ 'count' : [caldav_count]})
+
+## write things out to the data file
+pd.concat([data_original,
+ data_email_personal,
+ data_email_uw,
+ data_nextcloud]).to_csv(database_filename, index=False)