Commit 6d6109fc authored by Romain Bignon's avatar Romain Bignon

englishization, created Account class, parse ID

parent 4991422e
......@@ -49,8 +49,8 @@ class Application:
pass
parser = OptionParser(usage="%prog [options] <command> [args ...]")
parser.add_option('-l', '--login', help="Compte ID", type="str", default=login)
parser.add_option('-p', '--password', help="Compte password", type="str")
parser.add_option('-l', '--login', help="account ID", type="str", default=login)
parser.add_option('-p', '--password', help="account password", type="str")
return parser
def prompt_password(self, prompt):
......@@ -119,15 +119,15 @@ class Application:
sys.stderr.write('%s' % e)
def command_list(self):
comptes = self.bnp.get_comptes_list()
accounts = self.bnp.get_accounts_list()
print ' Compte Solde À venir '
print ' Account Balance Coming '
print '+---------------------+--------------+-------------+'
for compte in comptes:
print ' %-20s %11.2f %11.2f' % (compte['label'],
compte['solde'],
compte['avenir'])
for account in accounts:
print ' %-20s %11.2f %11.2f' % (account.label,
account.balance,
account.coming)
if __name__ == '__main__':
app = Application()
sys.exit(app.main(sys.argv))
......
......@@ -27,9 +27,9 @@ from bnporc.error import LoginError
class BNPorc(mechanize.Browser):
PAGES = {'identifiant=DOSSIER_Releves_D_Operation': pages.ComptesList,
'identifiant=DSP_HISTOCPT': pages.CompteHistory,
'identifiant=DSP_ET': pages.CompteCurrent,
PAGES = {'identifiant=DOSSIER_Releves_D_Operation': pages.AccountsList,
'identifiant=DSP_HISTOCPT': pages.AccountHistory,
'identifiant=DSP_ET': pages.AccountCurrent,
'Action=DSP_VGLOBALE': pages.LoginPage,
'type=homeconnex': pages.LoginPage,
}
......@@ -59,7 +59,7 @@ class BNPorc(mechanize.Browser):
if self.isOnPage(pages.LoginPage):
raise LoginError('Login or password incorrect.')
def get_comptes_list(self):
def get_accounts_list(self):
self.location('/NSFR?Action=DSP_VGLOBALE')
return self.page.get_list()
......
......@@ -18,8 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from .comptes_list import ComptesList
from .accounts_list import AccountsList
from .login import LoginPage
class CompteHistory(ComptesList): pass
class CompteCurrent(ComptesList): pass
class AccountHistory(AccountsList): pass
class AccountCurrent(AccountsList): pass
......@@ -20,7 +20,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .base import PageBase
class ComptesList(PageBase):
class Account(object):
def __init__(self):
self.id = 0
self.label = ''
self.balance = 0.0
self.coming = 0.0
self.history_link = ''
self.coming_link = ''
def setID(self, id):
assert isinstance(id, int)
self.id = id
def setLabel(self, label): self.label = label
def setBalance(self, balance):
assert isinstance(balance, float)
self.balance = balance
def setComing(self, coming):
assert isinstance(coming, float)
self.coming = coming
def setHistoryLink(self, link): self.history_link = link
def setComingLink(self, link): self.coming_link = link
class AccountsList(PageBase):
def loaded(self):
pass
......@@ -31,23 +58,25 @@ class ComptesList(PageBase):
for tr in trs:
if tr.getAttribute('class') == 'comptes':
fields = tr.getElementsByTagName('td')
label = ''
solde = ''
avenir = ''
account = Account()
for td in fields:
if td.getAttribute('headers').startswith('Libelle_'):
if td.getAttribute('headers').startswith('Numero_'):
id = td.childNodes[1].data
account.setID(int(''.join(id.split(' '))))
elif td.getAttribute('headers').startswith('Libelle_'):
a = td.getElementsByTagName('a')
label = a[0].firstChild.data
account.setLabel(label)
elif td.getAttribute('headers').startswith('Solde'):
a = td.getElementsByTagName('a')
solde = a[0].firstChild.data
solde = solde.replace('.','').replace(',','.')
balance = a[0].firstChild.data
balance = balance.replace('.','').replace(',','.')
account.setBalance(float(balance))
elif td.getAttribute('headers').startswith('Avenir'):
a = td.getElementsByTagName('a')
avenir = a[0].firstChild.data
avenir = avenir.replace('.','').replace(',','.')
coming = a[0].firstChild.data
coming = coming.replace('.','').replace(',','.')
account.setComing(float(coming))
l.append({'label': label,
'solde': float(solde),
'avenir': float(avenir)})
l.append(account)
return l
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