From: Benjamin Mako Hill Date: Sat, 31 Aug 2019 17:54:56 +0000 (-0700) Subject: initial version of count todo items script X-Git-Url: https://projects.mako.cc/source/count_todo_items/commitdiff_plain/d9575163834f81402ecb1d750fddb1db826f37db?ds=sidebyside initial version of count todo items script --- d9575163834f81402ecb1d750fddb1db826f37db diff --git a/count_todo_items.py b/count_todo_items.py new file mode 100755 index 0000000..4338456 --- /dev/null +++ b/count_todo_items.py @@ -0,0 +1,60 @@ +#!/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)