Commit ffd6bb19 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Romain Bignon

[fortuneo] port to python3

+ make a few improvements
parent fe93d9a0
......@@ -51,13 +51,9 @@ class Fortuneo(LoginBrowser):
def __init__(self, *args, **kwargs):
LoginBrowser.__init__(self, *args, **kwargs)
self.cache = {}
self.cache["investments"] = {}
self.investments = {}
def do_login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
if not self.login_page.is_here():
self.location('/fr/identification.jsp')
......@@ -73,12 +69,12 @@ class Fortuneo(LoginBrowser):
@need_login
def get_investments(self, account):
if hasattr(account, '_investment_link'):
if self.cache["investments"].get(account.id) == None:
if account.id in self.investments:
return self.investments[account.id]
else:
self.location(account._investment_link)
return self.page.get_investments(account)
else:
return iter(self.cache["investments"].get(account.id))
return iter([])
return []
@need_login
def get_history(self, account):
......@@ -87,7 +83,7 @@ class Fortuneo(LoginBrowser):
if self.page.select_period():
return self.page.get_operations(account)
return iter([])
return []
@need_login
def get_coming(self, account):
......@@ -99,20 +95,8 @@ class Fortuneo(LoginBrowser):
@need_login
def get_accounts_list(self):
"""accounts list"""
self.location('/fr/prive/default.jsp?ANav=1')
return self.page.get_list()
@need_login
def get_account(self, id):
"""Get an account from its ID"""
assert isinstance(id, basestring)
for a in list(self.get_accounts_list()):
if a.id == id:
return a
return None
# vim:ts=4:sw=4
......@@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.base import find_object
from weboob.capabilities.bank import CapBank, AccountNotFound
from weboob.tools.backend import Module, BackendConfig
from weboob.tools.value import ValueBackendPassword
......@@ -51,12 +52,7 @@ class FortuneoModule(Module, CapBank):
return self.browser.get_accounts_list()
def get_account(self, _id):
account = self.browser.get_account(_id)
if account:
return account
else:
raise AccountNotFound()
return find_object(self.iter_accounts(), id=_id, error=AccountNotFound)
def iter_history(self, account):
"""Iter history of transactions on a specific account"""
......
......@@ -17,7 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from urllib import urlencode
from __future__ import unicode_literals
import re
from time import sleep
from datetime import date
......@@ -78,7 +79,7 @@ class PeaHistoryPage(LoggedPage, HTMLPage):
inv = Investment()
inv.label = CleanText(None).filter(cols[self.COL_LABEL])
link = cols[self.COL_LABEL].xpath('./a[contains(@href, "cdReferentiel")]')[0]
inv.id = unicode(re.search('cdReferentiel=(.*)', link.attrib['href']).group(1))
inv.id = re.search('cdReferentiel=(.*)', link.attrib['href']).group(1)
inv.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1)
inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY], True)
inv.unitprice = self.parse_decimal(cols[self.COL_UNITPRICE], True)
......@@ -92,8 +93,8 @@ class PeaHistoryPage(LoggedPage, HTMLPage):
yield inv
inv = Investment()
inv.code = unicode("XX-liquidity")
inv.label = unicode("Liquidités", 'utf-8')
inv.code = "XX-liquidity"
inv.label = "Liquidités"
inv.valuation = CleanDecimal(None, True).filter(self.doc.xpath('//*[@id="valorisation_compte"]/table/tr[3]/td[2]'))
yield inv
......@@ -162,7 +163,7 @@ class InvestmentHistoryPage(LoggedPage, HTMLPage):
cols = line.findall('td')
inv = Investment()
inv.id = unicode(re.search('cdReferentiel=(.*)', cols[self.COL_LABEL].find('a').attrib['href']).group(1))
inv.id = re.search('cdReferentiel=(.*)', cols[self.COL_LABEL].find('a').attrib['href']).group(1)
inv.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1)
inv.label = CleanText(None).filter(cols[self.COL_LABEL])
inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY])
......@@ -209,6 +210,7 @@ class InvestmentHistoryPage(LoggedPage, HTMLPage):
if 'Valorisation' in CleanText('.')(div):
return RawText('./p/strong')(div)
class AccountHistoryPage(LoggedPage, HTMLPage):
def build_doc(self, content):
content = re.sub(br'\*<E040032TC MSBILL.INFO', b'*', content)
......@@ -321,7 +323,7 @@ class AccountsList(LoggedPage, HTMLPage):
params['div%s' % i] = input.attrib['value']
params['time'] = time
r = self.browser.open('/AsynchAjax?%s' % urlencode(params))
r = self.browser.open('/AsynchAjax', params=params)
data = json.loads(r.content)
for i, d in enumerate(data['data']):
......@@ -400,7 +402,7 @@ class AccountsList(LoggedPage, HTMLPage):
account.label = CleanText('./a[contains(@class, "numero_compte")]/@title')(cpt)
for pattern, type in self.ACCOUNT_TYPES.iteritems():
for pattern, type in self.ACCOUNT_TYPES.items():
if pattern in account._history_link:
account.type = type
break
......@@ -409,7 +411,7 @@ class AccountsList(LoggedPage, HTMLPage):
account._investment_link = Link('./ul/li/a[contains(@id, "portefeuille")]')(cpt)
balance = self.browser.open(account._investment_link).page.get_balance(account.type)
if account.type in {Account.TYPE_PEA, Account.TYPE_MARKET}:
self.browser.cache["investments"][account.id] = list(self.browser.open(account._investment_link).page.get_investments(account))
self.browser.investments[account.id] = list(self.browser.open(account._investment_link).page.get_investments(account))
else:
balance = self.browser.open(account._history_link).page.get_balance()
......@@ -425,7 +427,7 @@ class AccountsList(LoggedPage, HTMLPage):
if (account.label, account.id, account.balance) not in [(a.label, a.id, a.balance) for a in accounts]:
accounts.append(account)
return iter(accounts)
return accounts
class GlobalAccountsList(LoggedPage, HTMLPage):
......
......@@ -33,8 +33,8 @@ class LoginPage(HTMLPage):
raise BrowserUnavailable(msg)
form = self.get_form(name="acces_identification")
form['login'] = login.encode('utf-8')
form['passwd'] = passwd.encode('utf-8')
form['login'] = login
form['passwd'] = passwd
form.submit()
......
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