code clean, split too long lines

This commit is contained in:
Christophe Benz 2010-12-08 16:58:14 +01:00 committed by Romain Bignon
commit 851b2d34ca
10 changed files with 132 additions and 108 deletions

View file

@ -15,11 +15,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .login import LoginPage, LoggedPage, BadLoginPage, AccountDesactivate
from .cookie import CookiePage
from .accountlist import AccountList
from .accounthistory import AccountHistory
from .transfer import TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary
__all__ = ['LoginPage', 'LoggedPage', 'CookiePage', "AccountList", 'AccountHistory', 'BadLoginPage', 'AccountDesactivate', 'TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
__all__ = ['LoginPage', 'LoggedPage', 'CookiePage', "AccountList", 'AccountHistory', 'BadLoginPage',
'AccountDesactivate', 'TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']

View file

@ -15,18 +15,22 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
from weboob.capabilities.bank import Operation
from weboob.tools.browser import BasePage
__all__ = ['AccountHistory']
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub(' ', data)
def remove_extra_spaces(data):
p = re.compile(r'\s+')
return p.sub(' ', data)
@ -34,9 +38,10 @@ def remove_extra_spaces(data):
class AccountHistory(BasePage):
def on_loaded(self):
if self.document.docinfo.doctype == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">':
if self.document.docinfo.doctype == '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">':
self.browser.follow_link(url_regex="releve", tag="a")
def get_history(self):
mvt_table = self.document.xpath("//table[@id='mouvements']", smart_strings=False)[0]
mvt_ligne = mvt_table.xpath("./tbody/tr")
@ -49,7 +54,6 @@ class AccountHistory(BasePage):
tp = mvt.xpath("./td")[1]
operation.label = remove_extra_spaces(remove_html_tags(self.browser.parser.tostring(tp)))
r = re.compile(r'\d+')
tp = mvt.xpath("./td/span")
amount = None

View file

@ -20,14 +20,15 @@ from weboob.capabilities.bank import Account, AccountNotFound
from weboob.tools.browser import BasePage
__all__ = ['AccountList']
class AccountList(BasePage):
def on_loaded(self):
self.Account_List = []
self.account_list = []
def get_accounts_list(self):
#Parse CCP
compte_table = self.document.xpath("//table[@id='comptes']", smart_strings=False)[0]
compte_ligne = compte_table.xpath("./tbody/tr")
@ -38,8 +39,8 @@ class AccountList(BasePage):
account.label = tp.text
account.link_id = tp.get("href")
account.id = compte.xpath("./td")[1].text
account.balance = float(''.join( compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() ))
self.Account_List.append(account)
account.balance = float(''.join(compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split()))
self.account_list.append(account)
#Parse epargne
epargne_table = self.document.xpath("//table[@id='comptesEpargne']", smart_strings=False)[0]
@ -51,16 +52,16 @@ class AccountList(BasePage):
account.label = tp.text
account.link_id = tp.get("href")
account.id = epargne.xpath("./td")[1].text
account.balance = float(''.join( epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() ) )
self.Account_List.append(account)
account.balance = float(''.join(epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split()))
self.account_list.append(account)
return self.Account_List
return self.account_list
def get_account(self, id):
if not self.Account_List:
if not self.account_list:
self.get_accounts_list()
for account in self.Account_List:
if account.id == id:
return account
for account in self.account_list:
if account.id == id:
return account
raise AccountNotFound('Unable to find account: %s' % id)

View file

@ -16,11 +16,11 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.tools.browser import BasePage
__all__ = ['CookiePage']
class CookiePage(BasePage):
def on_loaded(self):
pass
pass

View file

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import hashlib
from weboob.tools.browser import BasePage
@ -35,26 +36,32 @@ class LoginPage(BasePage):
pass
def login(self, login, pwd):
LOCAL_HASH = ['a02574d7bf67677d2a86b7bfc5e864fe', 'eb85e1cc45dd6bdb3cab65c002d7ac8a', '596e6fbd54d5b111fe5df8a4948e80a4', '9cdc989a4310554e7f5484d0d27a86ce', '0183943de6c0e331f3b9fc49c704ac6d', '291b9987225193ab1347301b241e2187', '163279f1a46082408613d12394e4042a', 'b0a9c740c4cada01eb691b4acda4daea', '3c4307ee92a1f3b571a3c542eafcb330', 'dbccecfa2206bfdb4ca891476404cc68']
process = lambda i: md5(self.browser.retrieve(("https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?imgid=%d&0.25122230781963073" % i ))[0])
Keypad = [ process(i) for i in range(10)]
LOCAL_HASH = ['a02574d7bf67677d2a86b7bfc5e864fe', 'eb85e1cc45dd6bdb3cab65c002d7ac8a',
'596e6fbd54d5b111fe5df8a4948e80a4', '9cdc989a4310554e7f5484d0d27a86ce',
'0183943de6c0e331f3b9fc49c704ac6d', '291b9987225193ab1347301b241e2187',
'163279f1a46082408613d12394e4042a', 'b0a9c740c4cada01eb691b4acda4daea',
'3c4307ee92a1f3b571a3c542eafcb330', 'dbccecfa2206bfdb4ca891476404cc68',
]
process = lambda i: md5(self.browser.retrieve(('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb'
'/loginform?imgid=%d&0.25122230781963073' % i))[0])
keypad = [process(i) for i in range(10)]
correspondance = [keypad.index(i) for i in LOCAL_HASH]
newpassword = ''.join(str(correspondance[int(c)]) for c in pwd)
correspondance = [ Keypad.index(i) for i in LOCAL_HASH]
Newpassword = "".join([str(correspondance[int(c)]) for c in pwd])
self.browser.select_form(name="formAccesCompte")
self.browser.select_form(name='formAccesCompte')
self.browser.set_all_readonly(False)
self.browser["password"] = Newpassword
self.browser["username"] = login
self.browser['password'] = newpassword
self.browser['username'] = login
self.browser.submit()
class LoggedPage(BasePage):
pass
class BadLoginPage(BasePage):
pass
class AccountDesactivate(BasePage):
pass

View file

@ -16,17 +16,17 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
from weboob.capabilities.bank import TransferError
from weboob.tools.browser import BasePage
from weboob.tools.misc import to_unicode
import re
__all__ = ['TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
class TransferChooseAccounts(BasePage):
def set_accouts(self, from_account, to_account):
self.browser.select_form(name="AiguillageForm")
self.browser["idxCompteEmetteur"] = [from_account.id]
@ -35,16 +35,17 @@ class TransferChooseAccounts(BasePage):
class CompleteTransfer(BasePage):
def complete_transfer(self, amount):
self.browser.select_form(name="VirementNationalForm")
self.browser["montant"] = str(amount)
self.browser.submit()
class TransferConfirm(BasePage):
class TransferConfirm(BasePage):
def confirm(self):
self.browser.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
self.browser.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/'
'virementnational/4-virementNational.ea')
class TransferSummary(BasePage):
def get_transfer_id(self):
@ -56,7 +57,6 @@ class TransferSummary(BasePage):
except UnicodeDecodeError, error:
text = error.object.strip()
match = re.search("Votre virement N.+ ([0-9]+) ", text)
if match:
id_transfer = match.groups()[0]