ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Reminder/shellmc.py
(Generate patch)

Comparing:
FreeBSDAdmin/Reminder/citicards.py (file contents), Revision 1131 by douglas, 2008-12-21T01:48:02-08:00 vs.
FreeBSDAdmin/Reminder/shellmc.py (file contents), Revision 1178 by douglas, 2009-05-17T14:30:08-07:00

# Line 1 | Line 1
1 < # Citi Card
1 > # Shell MasterCard
2   #
3   # Douglas Thrift
4   #
5   # $Id$
6  
7 + from __future__ import with_statement
8 + from ClientForm import FormParser
9 + import common
10   from datetime import datetime
11 + from mechanize import LinkNotFoundError
12   import re
13   import website
14  
15 < class Bank(website.Website):
15 > class _FormParser(FormParser):
16 >        def __init__(self, *args, **kwargs):
17 >                FormParser.__init__(self, *args, **kwargs)
18 >
19 >        def do_input(self, attributes):
20 >                self.__enable(attributes)
21 >                FormParser.do_input(self, attributes)
22 >
23 >        def start_select(self, attributes):
24 >                self.__name = None
25 >
26 >                for name, value in attributes:
27 >                        if name == 'name':
28 >                                self.__name = value
29 >
30 >                self.__enable(attributes)
31 >                FormParser.start_select(self, attributes)
32 >
33 >        def end_select(self):
34 >                if self.__name == 'download_date':
35 >                        self.do_option([('value', 'Activity Since Last Statement')])
36 >                elif self.__name == 'download_format':
37 >                        self.do_option([('value', 'QIF')])
38 >
39 >                FormParser.end_select(self)
40 >
41 >        def __enable(self, attributes):
42 >                try:
43 >                        attributes.remove(('disabled', 'disabled'))
44 >                except ValueError:
45 >                        pass
46 >
47 > class Bank(website.Website, common.Bank):
48 >        PAYMENT_DUE = re.compile(r'[A-Z][a-z]{2}\. \d{1,2}, \d{4}')
49 >
50          def __init__(self, username, password, debug):
51 <                website.Website.__init__(self, debug)
51 >                website.Website.__init__(self, debug, factory = website.Factory(_FormParser))
52  
53 <                self.browser.open('https://www.citicards.com/')
53 >                self.browser.open('http://www.shellmc.accountonline.com/')
54                  self.browser.select_form(name = 'LOGIN')
55  
56                  self.browser['USERNAME'] = username
# Line 20 | Line 58 | class Bank(website.Website):
58  
59                  self.browser.submit()
60  
61 <        def __call__(self, account):
62 <                payment_due = re.compile(r'[A-Z][a-z]{2}\. \d{1,2}, \d{4}')
61 >        def __del__(self):
62 >                try:
63 >                        self.browser.follow_link(text_regex = 'Log Out')
64 >                except (AttributeError, LinkNotFoundError):
65 >                        pass
66 >
67 >        def download(self, account):
68 >                try:
69 >                        balance = self.Soup(self._follow_link(text_regex = account)).find(attrs = {'class': 'curr_balance'}).string
70 >
71 >                        self._follow_link(text_regex = 'View/Download Your Statement')
72 >                        self.browser.select_form(name = 'download_statement')
73 >
74 >                        self.browser.form.action = 'https://www.accountonline.com/cards/svc/StatementDownload.do?dateRange=unbilled&viewType=qif'
75 >                        self.browser['download_date'] = ['Activity Since Last Statement']
76 >                        self.browser['download_format'] = ['QIF']
77 >
78 >                        return 'unbilled.qif', self._submit().read(), balance
79 >                finally:
80 >                        self._back()
81  
82 +        def due(self, account):
83                  try:
84 <                        return datetime.strptime(payment_due.search(self.Soup(self.browser.follow_link(text_regex = account)).find(text = re.compile('Payment Due')).findNext(text = payment_due)).group(0), '%b. %d, %Y').date()
84 >                        return datetime.strptime(self.PAYMENT_DUE.search(self.Soup(self._follow_link(text_regex = account)).find(text = re.compile('Payment Due')).findNext(text = self.PAYMENT_DUE)).group(0), '%b. %d, %Y').date()
85                  finally:
86 <                        self.browser.back()
86 >                        self._back()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines