Introduce find_id_list
And code simplification in backends/browsers
This commit is contained in:
parent
cc1e587552
commit
080c4aff81
5 changed files with 27 additions and 60 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
from weboob.capabilities.bill import ICapBill, Subscription, SubscriptionNotFound, Detail
|
||||
from weboob.capabilities.base import find_id_list
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import ValueBackendPassword
|
||||
|
||||
|
|
@ -48,17 +49,15 @@ class PoivyBackend(BaseBackend, ICapBill):
|
|||
self.config['password'].get())
|
||||
|
||||
def iter_subscription(self):
|
||||
for subscription in self.browser.get_subscription_list():
|
||||
yield subscription
|
||||
return self.browser.get_subscription_list()
|
||||
|
||||
def get_subscription(self, _id):
|
||||
subscription = self.browser.get_subscription(_id)
|
||||
if subscription:
|
||||
return subscription
|
||||
else:
|
||||
raise SubscriptionNotFound()
|
||||
return find_id_list(self.iter_subscription(), _id, error=SubscriptionNotFound)
|
||||
|
||||
def iter_bills_history(self, subscription):
|
||||
# Try if we have a real subscription before to load the history
|
||||
if not isinstance(subscription, Subscription):
|
||||
subscription = self.get_subscription(subscription)
|
||||
return self.browser.get_history()
|
||||
|
||||
# No details on the website
|
||||
|
|
|
|||
|
|
@ -48,25 +48,7 @@ class PoivyBrowser(LoginBrowser):
|
|||
def get_subscription_list(self):
|
||||
return self.homepage.stay_or_go().get_list()
|
||||
|
||||
def _find_id_list(self, mylist, _id):
|
||||
for a in mylist:
|
||||
if a.id == _id:
|
||||
return a
|
||||
return None
|
||||
|
||||
@need_login
|
||||
def get_subscription(self, _id):
|
||||
return self._find_id_list(self.get_subscription_list(), _id)
|
||||
|
||||
@need_login
|
||||
def get_history(self):
|
||||
self.history.stay_or_go()
|
||||
return self.pagination(lambda: self.page.get_calls())
|
||||
|
||||
@need_login
|
||||
def iter_bills(self, parentid):
|
||||
return self.bills.stay_or_go().get_bills()
|
||||
|
||||
@need_login
|
||||
def get_bill(self, _id):
|
||||
return self._find_id_list(self.iter_bills(), _id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue