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 |
1178 |
from mechanize import LinkNotFoundError |
11 |
douglas |
1131 |
import re |
12 |
|
|
import website |
13 |
|
|
|
14 |
douglas |
1178 |
class _FormParser(FormParser): |
15 |
|
|
def __init__(self, *args, **kwargs): |
16 |
|
|
FormParser.__init__(self, *args, **kwargs) |
17 |
|
|
|
18 |
|
|
def do_input(self, attributes): |
19 |
|
|
self.__enable(attributes) |
20 |
|
|
FormParser.do_input(self, attributes) |
21 |
|
|
|
22 |
|
|
def start_select(self, attributes): |
23 |
|
|
self.__name = None |
24 |
|
|
|
25 |
|
|
for name, value in attributes: |
26 |
|
|
if name == 'name': |
27 |
|
|
self.__name = value |
28 |
|
|
|
29 |
|
|
self.__enable(attributes) |
30 |
|
|
FormParser.start_select(self, attributes) |
31 |
|
|
|
32 |
|
|
def end_select(self): |
33 |
|
|
if self.__name == 'download_date': |
34 |
|
|
self.do_option([('value', 'Activity Since Last Statement')]) |
35 |
|
|
elif self.__name == 'download_format': |
36 |
|
|
self.do_option([('value', 'QIF')]) |
37 |
|
|
|
38 |
|
|
FormParser.end_select(self) |
39 |
|
|
|
40 |
|
|
def __enable(self, attributes): |
41 |
|
|
try: |
42 |
|
|
attributes.remove(('disabled', 'disabled')) |
43 |
|
|
except ValueError: |
44 |
|
|
pass |
45 |
|
|
|
46 |
douglas |
1179 |
class Bank(website.Website, bank.Bank): |
47 |
|
|
PAYMENT_DUE = re.compile(r'([A-Z][a-z]{2})\.?( \d{1,2}, \d{4})') |
48 |
douglas |
1145 |
|
49 |
douglas |
1179 |
def __init__(self, config, debug): |
50 |
douglas |
1178 |
website.Website.__init__(self, debug, factory = website.Factory(_FormParser)) |
51 |
douglas |
1179 |
bank.Bank.__init__(self, config) |
52 |
douglas |
1131 |
|
53 |
douglas |
1145 |
self.browser.open('http://www.shellmc.accountonline.com/') |
54 |
douglas |
1131 |
self.browser.select_form(name = 'LOGIN') |
55 |
|
|
|
56 |
douglas |
1179 |
self.browser['USERNAME'] = self._username() |
57 |
|
|
self.browser['PASSWORD'] = self._password() |
58 |
douglas |
1131 |
|
59 |
|
|
self.browser.submit() |
60 |
|
|
|
61 |
douglas |
1178 |
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 |
douglas |
1145 |
def due(self, account): |
83 |
douglas |
1131 |
try: |
84 |
douglas |
1179 |
return datetime.strptime(''.join(self.PAYMENT_DUE.search(self.Soup(self._follow_link(text_regex = account)).find(text = re.compile('Payment Due')).findNext(text = self.PAYMENT_DUE)).group(1, 2)), '%b %d, %Y').date() |
85 |
douglas |
1131 |
finally: |
86 |
douglas |
1178 |
self._back() |