1 |
douglas |
1145 |
# Shell MasterCard |
2 |
douglas |
1131 |
# |
3 |
|
|
# Douglas Thrift |
4 |
|
|
# |
5 |
|
|
# $Id$ |
6 |
|
|
|
7 |
douglas |
1179 |
import bank |
8 |
douglas |
1178 |
from ClientForm import FormParser |
9 |
douglas |
1131 |
from datetime import datetime |
10 |
douglas |
1180 |
import decimal |
11 |
douglas |
1178 |
from mechanize import LinkNotFoundError |
12 |
douglas |
1131 |
import re |
13 |
|
|
import website |
14 |
|
|
|
15 |
douglas |
1178 |
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 |
douglas |
1179 |
class Bank(website.Website, bank.Bank): |
48 |
|
|
PAYMENT_DUE = re.compile(r'([A-Z][a-z]{2})\.?( \d{1,2}, \d{4})') |
49 |
douglas |
1145 |
|
50 |
douglas |
1179 |
def __init__(self, config, debug): |
51 |
douglas |
1178 |
website.Website.__init__(self, debug, factory = website.Factory(_FormParser)) |
52 |
douglas |
1179 |
bank.Bank.__init__(self, config) |
53 |
douglas |
1131 |
|
54 |
douglas |
1145 |
self.browser.open('http://www.shellmc.accountonline.com/') |
55 |
douglas |
1131 |
self.browser.select_form(name = 'LOGIN') |
56 |
|
|
|
57 |
douglas |
1179 |
self.browser['USERNAME'] = self._username() |
58 |
|
|
self.browser['PASSWORD'] = self._password() |
59 |
douglas |
1131 |
|
60 |
|
|
self.browser.submit() |
61 |
|
|
|
62 |
douglas |
1178 |
def __del__(self): |
63 |
|
|
try: |
64 |
|
|
self.browser.follow_link(text_regex = 'Log Out') |
65 |
|
|
except (AttributeError, LinkNotFoundError): |
66 |
|
|
pass |
67 |
|
|
|
68 |
|
|
def download(self, account): |
69 |
|
|
try: |
70 |
douglas |
1184 |
balance = -decimal.Decimal(str(self.Soup(self._follow_link(text_regex = str(account))).find(attrs = {'class': 'curr_balance'}).string[1:]).translate(None, ',')) |
71 |
douglas |
1178 |
|
72 |
|
|
self._follow_link(text_regex = 'View/Download Your Statement') |
73 |
|
|
self.browser.select_form(name = 'download_statement') |
74 |
|
|
|
75 |
|
|
self.browser.form.action = 'https://www.accountonline.com/cards/svc/StatementDownload.do?dateRange=unbilled&viewType=qif' |
76 |
|
|
self.browser['download_date'] = ['Activity Since Last Statement'] |
77 |
|
|
self.browser['download_format'] = ['QIF'] |
78 |
|
|
|
79 |
douglas |
1180 |
return self._submit().read(), balance |
80 |
douglas |
1178 |
finally: |
81 |
|
|
self._back() |
82 |
|
|
|
83 |
douglas |
1145 |
def due(self, account): |
84 |
douglas |
1131 |
try: |
85 |
douglas |
1180 |
return datetime.strptime(''.join(self.PAYMENT_DUE.search(self.Soup(self._follow_link(text_regex = str(account))).find(text = re.compile('Payment Due')).findNext(text = self.PAYMENT_DUE)).group(1, 2)), '%b %d, %Y').date() |
86 |
douglas |
1131 |
finally: |
87 |
douglas |
1178 |
self._back() |