4 |
|
# |
5 |
|
# $Id$ |
6 |
|
|
7 |
< |
from __future__ import with_statement |
7 |
> |
import bank |
8 |
|
from ClientForm import FormParser |
9 |
– |
import common |
9 |
|
from datetime import datetime |
10 |
+ |
import decimal |
11 |
|
from mechanize import LinkNotFoundError |
12 |
|
import re |
13 |
|
import website |
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}') |
47 |
> |
class Bank(website.Website, bank.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): |
50 |
> |
def __init__(self, config, debug): |
51 |
|
website.Website.__init__(self, debug, factory = website.Factory(_FormParser)) |
52 |
+ |
bank.Bank.__init__(self, config) |
53 |
|
|
54 |
|
self.browser.open('http://www.shellmc.accountonline.com/') |
55 |
|
self.browser.select_form(name = 'LOGIN') |
56 |
|
|
57 |
< |
self.browser['USERNAME'] = username |
58 |
< |
self.browser['PASSWORD'] = password |
57 |
> |
self.browser['USERNAME'] = self._username() |
58 |
> |
self.browser['PASSWORD'] = self._password() |
59 |
|
|
60 |
|
self.browser.submit() |
61 |
|
|
67 |
|
|
68 |
|
def download(self, account): |
69 |
|
try: |
70 |
< |
balance = self.Soup(self._follow_link(text_regex = account)).find(attrs = {'class': 'curr_balance'}).string |
70 |
> |
balance = -decimal.Decimal(str(self.Soup(self._follow_link(text_regex = str(account))).find(attrs = {'class': 'curr_balance'}).string[1:]).translate(None, ',')) |
71 |
|
|
72 |
|
self._follow_link(text_regex = 'View/Download Your Statement') |
73 |
|
self.browser.select_form(name = 'download_statement') |
76 |
|
self.browser['download_date'] = ['Activity Since Last Statement'] |
77 |
|
self.browser['download_format'] = ['QIF'] |
78 |
|
|
79 |
< |
return 'unbilled.qif', self._submit().read(), balance |
79 |
> |
return self._submit().read(), balance |
80 |
|
finally: |
81 |
|
self._back() |
82 |
|
|
83 |
|
def due(self, account): |
84 |
|
try: |
85 |
< |
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 |
> |
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 |
|
finally: |
87 |
|
self._back() |