1 |
douglas |
1131 |
#!/usr/local/bin/python |
2 |
douglas |
1179 |
# Credit Cards |
3 |
douglas |
1131 |
# |
4 |
|
|
# Douglas Thrift |
5 |
|
|
# |
6 |
|
|
# $Id$ |
7 |
|
|
|
8 |
|
|
import atom |
9 |
|
|
from datetime import date, timedelta |
10 |
|
|
import gdata.calendar |
11 |
|
|
|
12 |
douglas |
1179 |
def main(calendar, config, banks, debug): |
13 |
|
|
for module in config.getlist('banks'): |
14 |
|
|
bank = banks.bank(module) |
15 |
douglas |
1145 |
|
16 |
douglas |
1179 |
for name, account in bank.accounts(): |
17 |
douglas |
1145 |
due = bank.due(account) |
18 |
douglas |
1131 |
today = date.today() |
19 |
|
|
|
20 |
|
|
if due <= today: |
21 |
|
|
continue |
22 |
|
|
|
23 |
|
|
title = '%s Due' % name |
24 |
|
|
query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full', '"%s"' % title) |
25 |
|
|
query.start_min = str(today) |
26 |
douglas |
1179 |
events = calendar.CalendarQuery(query).entry |
27 |
douglas |
1131 |
|
28 |
|
|
if events == []: |
29 |
|
|
event = gdata.calendar.CalendarEventEntry() |
30 |
|
|
event.title = atom.Title(text = title) |
31 |
|
|
event.transparency = gdata.calendar.Transparency() |
32 |
|
|
event.transparency.value = 'TRANSPARENT' |
33 |
|
|
event.visibility = gdata.calendar.Visibility() |
34 |
|
|
event.visibility.value = 'PRIVATE' |
35 |
|
|
|
36 |
|
|
event.when.append(gdata.calendar.When(start_time = str(due), end_time = str(due + timedelta(1)))) |
37 |
|
|
event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10)) |
38 |
|
|
|
39 |
douglas |
1179 |
calendar.InsertEvent(event, '/calendar/feeds/default/private/full') |
40 |
douglas |
1131 |
else: |
41 |
|
|
for index, event in enumerate(filter(lambda event: event.title.text == title, events)): |
42 |
|
|
if index == 0: |
43 |
|
|
event.transparency.value = 'TRANSPARENT' |
44 |
|
|
event.visibility.value = 'PRIVATE' |
45 |
|
|
event.when[0].start_time = str(due) |
46 |
|
|
event.when[0].end_time = str(due + timedelta(1)) |
47 |
|
|
|
48 |
|
|
if event.when[0].reminder != []: |
49 |
|
|
event.when[0].reminder[0].minutes = str(10) |
50 |
|
|
else: |
51 |
|
|
event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10)) |
52 |
|
|
|
53 |
douglas |
1179 |
calendar.UpdateEvent(event.GetEditLink().href, event) |
54 |
douglas |
1131 |
else: |
55 |
douglas |
1179 |
calendar.DeleteEvent(event.GetEditLink().href) |