diff --git a/modules/amazon/browser.py b/modules/amazon/browser.py index 630cfc74b0978d37d7e3b1aa4fe309d37848a7c4..eff14d0805537290e2e3cdc692da1a87904a6b60 100644 --- a/modules/amazon/browser.py +++ b/modules/amazon/browser.py @@ -18,12 +18,15 @@ # along with this weboob module. If not, see . from __future__ import unicode_literals + +import time from datetime import date from weboob.browser import LoginBrowser, URL, need_login, StatesMixin from weboob.exceptions import ( BrowserIncorrectPassword, BrowserUnavailable, ImageCaptchaQuestion, BrowserQuestion, - WrongCaptchaResponse, AuthMethodNotImplemented, NeedInteractiveFor2FA, BrowserPasswordExpired, + WrongCaptchaResponse, AuthMethodNotImplemented, NeedInteractiveFor2FA, + BrowserPasswordExpired, AppValidation, AppValidationExpired, ) from weboob.tools.value import Value from weboob.browser.browsers import ClientError @@ -107,6 +110,10 @@ def handle_security(self): # many captcha, reset value self.config['captcha_response'] = Value(value=None) else: + msg_validation = self.page.get_msg_app_validation() + if 'approve the notification' in msg_validation: + raise AppValidation(msg_validation) + otp_type = self.page.get_otp_type() if otp_type == '/ap/signin': # this otp will be always present until user deactivate it @@ -138,6 +145,19 @@ def handle_captcha(self, captcha): image = self.open(captcha[0]).content raise ImageCaptchaQuestion(image) + def check_app_validation(self): + # client has 60 seconds to unlock this page + timeout = time.time() + 60.00 + while time.time() < timeout: + link = self.page.get_link_app_validation() + self.location(link) + if self.security.is_here(): + time.sleep(2) + else: + return + else: + raise AppValidationExpired() + def do_login(self): if self.config['pin_code'].get(): # Resolve pin_code @@ -189,6 +209,9 @@ def do_login(self): self.page.login(self.username, self.password) + if self.config['resume'].get(): + self.check_app_validation() + if self.password_expired.is_here(): raise BrowserPasswordExpired(self.page.get_message()) diff --git a/modules/amazon/module.py b/modules/amazon/module.py index 35cf58959120cfb6143126fdb722d9e8b0d8a019..49f0cd37c7f0ec6ac1d6022b2e0c0248d32dcbb6 100644 --- a/modules/amazon/module.py +++ b/modules/amazon/module.py @@ -24,7 +24,7 @@ from weboob.capabilities.base import find_object, NotAvailable from weboob.tools.backend import Module, BackendConfig from weboob.tools.compat import urljoin -from weboob.tools.value import ValueBackendPassword, Value +from weboob.tools.value import ValueBackendPassword, Value, ValueTransient from weboob.tools.pdf import html_to_pdf from .browser import AmazonBrowser @@ -64,6 +64,7 @@ class AmazonModule(Module, CapDocument): Value('captcha_response', label='Captcha Response', required=False, default=''), Value('pin_code', label='OTP response', required=False, default=''), Value('request_information', label='request_information', default=None, required=False, noprompt=True), + ValueTransient('resume'), ) accepted_document_types = (DocumentTypes.BILL,) diff --git a/modules/amazon/pages.py b/modules/amazon/pages.py index 0ca7b0241c642a79a66da044d2b30f255bd95c71..bc55533d8911078a8bd19881bbac025b4a3535ac 100644 --- a/modules/amazon/pages.py +++ b/modules/amazon/pages.py @@ -58,6 +58,14 @@ def get_otp_type(self): assert url in ('verify', '/ap/signin'), url return url + def get_msg_app_validation(self): + msg = CleanText('//span[contains(@class, "transaction-approval-word-break")]')(self.doc) + if "To complete the sign-in, approve the notification sent to" in msg: + return msg + + def get_link_app_validation(self): + return Link('//a[contains(text(), "Click here to refresh the page")]')(self.doc) + def get_otp_message(self): return CleanText('//div[@class="a-box-inner"]/p')(self.doc)