#!/usr/local/bin/python
# Wesabe
#
# Douglas Thrift
#
# $Id$

from M2Crypto import m2urllib2, SSL

class Wesabe(object):
	def __init__(self, username, password, debug):
		context = SSL.Context()

		context.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, depth = 9)
		context.load_verify_locations('/etc/ssl/cert.pem')

		self.opener = m2urllib2.build_opener(context)

	def upload(self, name, filename, data, balance = None):
		print name, filename, balance

def main(calendar, config, banks, debug):
	wesabe = Wesabe(config.get('username'), config.getpassword('password'), debug)

	for module in config.getlist('banks'):
		bank = banks.bank(module)

		for name, account in bank.accounts():
			wesabe.upload(account, *bank.download(account))
