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