Commit 2493d6ca authored by Romain Bignon's avatar Romain Bignon

added the BNPorc class

parent 1f0c2841
# -*- coding: utf-8 -*-
"""
Copyright(C) 2009 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import mechanize
import ClientForm
import html5lib
import re
import pages
from .captcha import Captcha, TileError
class BNPorc(mechanize.Browser):
PAGES = {'DOSSIER_Releves_D_Operation': pages.ComptesList,
'DSP_HISTOCPT': pages.CompteHistory,
'DSP_ET': pages.CompteCurrent
}
def __init__(self, login, password):
mechanize.Browser.__init__(self)
assert isinstance(login, (str,unicode))
assert isinstance(password, (str,unicode))
assert password.isdigit()
self.parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))
self.open('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex')
img = Captcha(self.open('/NSImgGrille'))
self.back()
try:
img.build_tiles()
except TileError, err:
print >>sys.stderr, "Error: %s" % err
if err.tile:
err.tile.display()
self.select_form('logincanalnet')
# HACK because of fucking malformed HTML, the field isn't recognized by mechanize.
self.controls.append(ClientForm.TextControl('text', 'ch1', {'value': ''}))
self.set_all_readonly(False)
self['ch1'] = login
self['ch5'] = img.get_codes(password)
r = self.submit()
self.__set_location(self.open('/NSFR?Action=DSP_VGLOBALE'))
def get_comptes_list(self):
self.__set_location(self.open('/NSFR?Action=DSP_VGLOBALE'))
return self.page.get_list()
def __set_location(self, result):
pageCls = None
for key, value in self.PAGES.iteritems():
regexp = re.compile(".*identifiant=(.*)")
m = regexp.match(result.geturl())
if m and m.group(1).startswith(key):
pageCls = value
break
assert pageCls
document = self.parser.parse(result, encoding='iso-8859-1')
self.page = pageCls(self, document)
self.page.loaded()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment