ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Reminder/creditcards.py
Revision: 1178
Committed: 2009-05-17T14:30:08-07:00 (16 years, 1 month ago) by douglas
Content type: text/x-python
Original Path: FreeBSDAdmin/Reminder/creditcard.py
File size: 2103 byte(s)
Log Message:
Checkpoint the current state of the code.

File Contents

# User Rev Content
1 douglas 1131 #!/usr/local/bin/python
2     # Credit Card
3     #
4     # Douglas Thrift
5     #
6     # $Id$
7    
8     import atom
9 douglas 1178 import common
10 douglas 1131 from datetime import date, timedelta
11     import gdata.calendar
12     import gdata.calendar.service
13    
14     if __name__ == '__main__':
15 douglas 1178 parser = common.OptionParser()
16 douglas 1131 options = parser.parse_args()[0]
17 douglas 1145
18 douglas 1178 config, banks = common.config(parser, options, '.creditcard')
19 douglas 1131 service = gdata.calendar.service.CalendarService()
20    
21 douglas 1178 service.ClientLogin(config.get('google', 'username'), common.decode(config.get('google', 'password')))
22 douglas 1131
23 douglas 1145 for bank, accounts in banks.iteritems():
24 douglas 1178 bank = common.bank(bank, options, config)
25 douglas 1131
26 douglas 1145 for account in accounts:
27 douglas 1131 name, account = account.rsplit(' ', 1)
28 douglas 1145 due = bank.due(account)
29 douglas 1131 today = date.today()
30    
31     if due <= today:
32     continue
33    
34     title = '%s Due' % name
35     query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full', '"%s"' % title)
36     query.start_min = str(today)
37     events = service.CalendarQuery(query).entry
38    
39     if events == []:
40     event = gdata.calendar.CalendarEventEntry()
41     event.title = atom.Title(text = title)
42     event.transparency = gdata.calendar.Transparency()
43     event.transparency.value = 'TRANSPARENT'
44     event.visibility = gdata.calendar.Visibility()
45     event.visibility.value = 'PRIVATE'
46    
47     event.when.append(gdata.calendar.When(start_time = str(due), end_time = str(due + timedelta(1))))
48     event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10))
49    
50     service.InsertEvent(event, '/calendar/feeds/default/private/full')
51     else:
52     for index, event in enumerate(filter(lambda event: event.title.text == title, events)):
53     if index == 0:
54     event.transparency.value = 'TRANSPARENT'
55     event.visibility.value = 'PRIVATE'
56     event.when[0].start_time = str(due)
57     event.when[0].end_time = str(due + timedelta(1))
58    
59     if event.when[0].reminder != []:
60     event.when[0].reminder[0].minutes = str(10)
61     else:
62     event.when[0].reminder.append(gdata.calendar.Reminder(minutes = 10))
63    
64     service.UpdateEvent(event.GetEditLink().href, event)
65     else:
66     service.DeleteEvent(event.GetEditLink().href)

Properties

Name Value
svn:executable *
svn:keywords Id