citelis: Get account "balance"
This commit is contained in:
parent
27b3101d6a
commit
269de1d283
2 changed files with 41 additions and 4 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.capabilities.bank import Account
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
|
|
||||||
from .pages import LoginPage, SummaryPage, UselessPage
|
from .pages import LoginPage, SummaryPage, UselessPage
|
||||||
|
|
@ -34,8 +35,8 @@ class CitelisBrowser(BaseBrowser):
|
||||||
|
|
||||||
PAGES = {
|
PAGES = {
|
||||||
'%s://%s/userManager\.do\?reqCode=prepareLogin.*' % (PROTOCOL, DOMAIN): LoginPage,
|
'%s://%s/userManager\.do\?reqCode=prepareLogin.*' % (PROTOCOL, DOMAIN): LoginPage,
|
||||||
'%s://%s//summarySearch\.do\?reqCode=search.*' % (PROTOCOL, DOMAIN): SummaryPage,
|
'%s://%s/summarySearch\.do\?reqCode=search.*' % (PROTOCOL, DOMAIN): SummaryPage,
|
||||||
'%s://%s//userManager\.do\?reqCode=goToHomePage.+' % (PROTOCOL, DOMAIN): UselessPage,
|
'%s://%s/userManager\.do\?reqCode=goToHomePage.+' % (PROTOCOL, DOMAIN): UselessPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, merchant_id, *args, **kwargs):
|
def __init__(self, merchant_id, *args, **kwargs):
|
||||||
|
|
@ -54,4 +55,9 @@ class CitelisBrowser(BaseBrowser):
|
||||||
|
|
||||||
def get_accounts_list(self):
|
def get_accounts_list(self):
|
||||||
self.location('%s://%s/summarySearch.do?reqCode=search' % (self.PROTOCOL, self.DOMAIN))
|
self.location('%s://%s/summarySearch.do?reqCode=search' % (self.PROTOCOL, self.DOMAIN))
|
||||||
# TODO
|
account = Account()
|
||||||
|
account.id = u'1'
|
||||||
|
account.currency = Account.CUR_EUR
|
||||||
|
account.balance = self.page.get_balance()
|
||||||
|
account.label = u'Synthèse financière'
|
||||||
|
return [account]
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,26 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
import re
|
||||||
|
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['LoginPage', 'SummaryPage', 'UselessPage']
|
__all__ = ['LoginPage', 'SummaryPage', 'UselessPage']
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction(FrenchTransaction):
|
||||||
|
@classmethod
|
||||||
|
def clean_amount(cls, text):
|
||||||
|
text = text.strip()
|
||||||
|
# Convert "American" UUU.CC format to "French" UUU,CC format
|
||||||
|
if re.search(r'\d\.\d\d$', text):
|
||||||
|
text = text.replace(',', ' ').replace('.', ',')
|
||||||
|
return FrenchTransaction.clean_amount(text)
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(BasePage):
|
class LoginPage(BasePage):
|
||||||
def login(self, merchant_id, login, password):
|
def login(self, merchant_id, login, password):
|
||||||
self.browser.select_form(name='loginForm')
|
self.browser.select_form(name='loginForm')
|
||||||
|
|
@ -34,7 +48,24 @@ class LoginPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
class SummaryPage(BasePage):
|
class SummaryPage(BasePage):
|
||||||
pass
|
def clean_amount(self, el, debit):
|
||||||
|
amount = Decimal(Transaction.clean_amount(el.text_content()))
|
||||||
|
if amount == Decimal('0.00'):
|
||||||
|
return None
|
||||||
|
if debit and amount > Decimal('0'):
|
||||||
|
return -1 * amount
|
||||||
|
return amount
|
||||||
|
|
||||||
|
def get_balance(self):
|
||||||
|
zone = self.parser.select(self.document.getroot(), '#ActionZone_Euro', 1)
|
||||||
|
for tr in self.parser.select(zone, '#transactionError tr'):
|
||||||
|
tds = self.parser.select(tr, 'td')
|
||||||
|
if tds and tds[0].text_content().strip() == 'Total':
|
||||||
|
debit, credit = self.parser.select(tr, 'td.amount', 4)[-2:] # keep the last 2
|
||||||
|
debit = self.clean_amount(debit, debit=True)
|
||||||
|
credit = self.clean_amount(credit, debit=False)
|
||||||
|
amount = credit or debit
|
||||||
|
return amount
|
||||||
|
|
||||||
|
|
||||||
class UselessPage(BasePage):
|
class UselessPage(BasePage):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue