1 |
– |
#!/usr/local/bin/python |
1 |
|
# Wesabe |
2 |
|
# |
3 |
|
# Douglas Thrift |
4 |
|
# |
5 |
|
# $Id$ |
6 |
|
|
7 |
< |
import common |
9 |
< |
from M2Crypto import m2urllib2, SSL |
7 |
> |
import dtwesabe |
8 |
|
|
9 |
< |
class Wesabe(object): |
10 |
< |
def __init__(self, username, password, debug): |
11 |
< |
context = SSL.Context() |
9 |
> |
def main(calendar, config, banks, debug): |
10 |
> |
wesabe = dtwesabe.Wesabe(config.getusername(), config.getpassword()) |
11 |
> |
accounts = {} |
12 |
|
|
13 |
< |
context.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, depth = 9) |
14 |
< |
context.load_verify_locations('/etc/ssl/cert.pem') |
13 |
> |
for account in wesabe.accounts(): |
14 |
> |
if account.account_number is not None: |
15 |
> |
accounts[account.account_number] = account |
16 |
|
|
17 |
< |
self.opener = m2urllib2.build_opener(context) |
17 |
> |
for module in config.getlist('banks'): |
18 |
> |
bank = banks.bank(module) |
19 |
|
|
20 |
< |
def upload(self, name, filename, data, balance = None): |
21 |
< |
print name, filename, balance |
20 |
> |
for name, number in bank.accounts(): |
21 |
> |
account = accounts[number] |
22 |
|
|
23 |
< |
if __name__ == '__main__': |
24 |
< |
parser = common.OptionParser() |
25 |
< |
options = parser.parse_args()[0] |
26 |
< |
|
27 |
< |
config, banks = common.config(parser, options, '.wesabe') |
28 |
< |
wesabe = Wesabe(config.get('wesabe', 'username'), common.decode(config.get('wesabe', 'password')), True)#options.debug) |
29 |
< |
|
30 |
< |
for bank, accounts in banks.iteritems(): |
31 |
< |
bank = common.bank(bank, options, config) |
32 |
< |
|
33 |
< |
for account in accounts: |
34 |
< |
name, account = account.rsplit(' ', 1) |
35 |
< |
|
36 |
< |
wesabe.upload(name, *bank.download(account)) |
23 |
> |
wesabe.upload(number, account.account_type, account.financial_institution.id, *bank.download(number)) |