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 |
|
|
for module in config.getlist('banks'): |
13 |
|
|
bank = banks.bank(module) |
14 |
douglas |
1145 |
|
15 |
douglas |
1180 |
for name, number in bank.accounts(): |
16 |
|
|
due = bank.due(number) |
17 |
douglas |
1131 |
today = date.today() |
18 |
|
|
|
19 |
|
|
if due <= today: |
20 |
|
|
continue |
21 |
|
|
|
22 |
|
|
title = '%s Due' % name |
23 |
|
|
query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full', '"%s"' % title) |
24 |
|
|
query.start_min = str(today) |
25 |
douglas |
1179 |
events = calendar.CalendarQuery(query).entry |
26 |
douglas |
1131 |
|
27 |
|
|
if events == []: |
28 |
|
|
event = gdata.calendar.CalendarEventEntry() |
29 |
|
|
event.title = atom.Title(text = title) |
30 |
|
|
event.transparency = gdata.calendar.Transparency() |
31 |
|
|
event.transparency.value = 'TRANSPARENT' |
32 |
|
|
event.visibility = gdata.calendar.Visibility() |
33 |
|
|
event.visibility.value = 'PRIVATE' |
34 |
|
|
|
35 |
|
|
event.when.append(gdata.calendar.When(start_time = str(due), end_time = str(due + timedelta(1)))) |
36 |
|
|
event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10)) |
37 |
|
|
|
38 |
douglas |
1179 |
calendar.InsertEvent(event, '/calendar/feeds/default/private/full') |
39 |
douglas |
1131 |
else: |
40 |
|
|
for index, event in enumerate(filter(lambda event: event.title.text == title, events)): |
41 |
|
|
if index == 0: |
42 |
|
|
event.transparency.value = 'TRANSPARENT' |
43 |
|
|
event.visibility.value = 'PRIVATE' |
44 |
|
|
event.when[0].start_time = str(due) |
45 |
|
|
event.when[0].end_time = str(due + timedelta(1)) |
46 |
|
|
|
47 |
|
|
if event.when[0].reminder != []: |
48 |
|
|
event.when[0].reminder[0].minutes = str(10) |
49 |
|
|
else: |
50 |
|
|
event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10)) |
51 |
|
|
|
52 |
douglas |
1179 |
calendar.UpdateEvent(event.GetEditLink().href, event) |
53 |
douglas |
1131 |
else: |
54 |
douglas |
1179 |
calendar.DeleteEvent(event.GetEditLink().href) |