initial version of count todo items script
[count_todo_items] / count_todo_items.py
1 #!/usr/bin/env python3
2
3 import datetime
4 import mailbox
5 import numpy as np
6 import pandas as pd
7
8 # import caldav stuff
9 import caldav
10 from caldav.elements import dav, cdav
11
12 nimbus_password = '7TS3L-xABPz-8PJwn-zxAz7-ZY2Y5'
13 database_filename = "list_of_databases.csv"
14
15 current_timestamp = datetime.datetime.now()
16 data_original = pd.read_csv(database_filename)
17
18 def get_flags_for_maildir (maildir_name):
19     mb_counts = { 'unread' : 0, 'flagged' : 0 }
20
21     mb = mailbox.Maildir(maildir_name)
22
23     for msg in mb:
24         flags = msg.get_flags()
25         if "S" not in flags:
26             mb_counts['unread'] += 1
27         if "F" in flags:
28             mb_counts['flagged'] += 1
29
30     return mb_counts
31
32 def rows_from_mb_counts (source_string, mb_counts):
33     return pd.DataFrame({'time' : current_timestamp,
34                          'source' : source_string,
35                          'feature' : list(mb_counts.keys()),
36                          'count' : list(mb_counts.values())})
37
38 data_email_personal = rows_from_mb_counts("default inbox",
39                                           get_flags_for_maildir("~/incoming/mail/default"))
40
41 data_email_uw = rows_from_mb_counts("UW inbox",
42                                     get_flags_for_maildir("~/incoming/mail/uw-inbox"))
43
44 # load calendar data
45 caldav_client = caldav.DAVClient("https://mako:{pw}@nimbus.mako.cc/remote.php/dav/calendars/mako/personal/".format(pw=nimbus_password))
46 cal = caldav_client.principal().calendars()[0]
47
48 caldav_count = np.sum(["PERCENT-COMPLETE:100" not in c.data
49                        for c in cal.todos(include_completed=True)])
50
51 data_nextcloud = pd.DataFrame({'time' : [current_timestamp],
52                                'source' : ['nextcloud tasks'],
53                                'feature' : ['open'],
54                                'count' : [caldav_count]})
55
56 ## write things out to the data file
57 pd.concat([data_original,
58            data_email_personal,
59            data_email_uw,
60            data_nextcloud]).to_csv(database_filename, index=False)

Benjamin Mako Hill || Want to submit a patch?