From dc091a2a4a4128ba19d27a0ac39909dd41079011 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Thu, 25 May 2023 00:28:11 +0200 Subject: [PATCH] Fix checks, bump versions --- lidlplus/__main__.py | 13 +++++++++++-- lidlplus/api.py | 24 ++++++++++++++++++------ lidlplus/exceptions.py | 4 ++++ requirements.txt | 10 +++++----- setup.py | 4 ++-- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/lidlplus/__main__.py b/lidlplus/__main__.py index 1983fa5..4db7323 100755 --- a/lidlplus/__main__.py +++ b/lidlplus/__main__.py @@ -27,10 +27,19 @@ def get_arguments(): parser.add_argument("-l", "--language", metavar="LANG", help="language (de, en, fr, it, ...)") parser.add_argument("-u", "--user", help="Lidl Plus login username") parser.add_argument("-p", "--password", metavar="XXX", help="Lidl Plus login password") - parser.add_argument("--2fa", choices=["phone", "email"], default="phone", help="choose two factor auth method") + parser.add_argument( + "--2fa", + choices=["phone", "email"], + default="phone", + help="choose two factor auth method", + ) parser.add_argument("-r", "--refresh-token", metavar="TOKEN", help="refresh token to authenticate") parser.add_argument("--skip-verify", help="skip ssl verification", action="store_true") - parser.add_argument("--not-accept-legal-terms", help="not auto accept legal terms updates", action="store_true") + parser.add_argument( + "--not-accept-legal-terms", + help="not auto accept legal terms updates", + action="store_true", + ) parser.add_argument("-d", "--debug", help="debug mode", action="store_true") subparser = parser.add_subparsers(title="commands", metavar="command", required=True) auth = subparser.add_parser("auth", help="authenticate and get token") diff --git a/lidlplus/api.py b/lidlplus/api.py index 0da2901..7ee2cb4 100644 --- a/lidlplus/api.py +++ b/lidlplus/api.py @@ -9,7 +9,12 @@ import requests -from lidlplus.exceptions import WebBrowserException, LoginError, LegalTermsException +from lidlplus.exceptions import ( + WebBrowserException, + LoginError, + LegalTermsException, + MissingLogin, +) try: from getuseragent import UserAgent @@ -57,7 +62,6 @@ def token(self): return self._token def _register_oauth_client(self): - if self._login_url: return self._login_url client = Client(client_authn_method=CLIENT_AUTHN_METHOD, client_id=self._CLIENT_ID) @@ -84,7 +88,6 @@ def _init_chrome(self, headless=True): return webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options) def _init_firefox(self, headless=True): - user_agent = UserAgent(self._OS.lower()).Random() logging.getLogger("WDM").setLevel(logging.NOTSET) options = webdriver.FirefoxOptions() @@ -203,11 +206,20 @@ def login(self, phone, password, **kwargs): wait.until(expected_conditions.visibility_of_element_located((By.ID, "button_welcome_login"))).click() wait.until(expected_conditions.visibility_of_element_located((By.NAME, "EmailOrPhone"))).send_keys(phone) self._click(browser, (By.ID, "button_btn_submit_email")) - self._click(browser, (By.ID, "button_btn_submit_email"), request=f"{self._AUTH_API}/api/phone/exists.*") + self._click( + browser, + (By.ID, "button_btn_submit_email"), + request=f"{self._AUTH_API}/api/phone/exists.*", + ) wait.until(expected_conditions.element_to_be_clickable((By.ID, "field_Password"))).send_keys(password) self._click(browser, (By.ID, "button_submit")) self._check_login_error(browser) - self._check_2fa_auth(browser, wait, kwargs.get("verify_mode", "phone"), kwargs.get("verify_token_func")) + self._check_2fa_auth( + browser, + wait, + kwargs.get("verify_mode", "phone"), + kwargs.get("verify_token_func"), + ) browser.wait_for_request(f"{self._AUTH_API}/connect.*") code = self._parse_code(browser, wait, accept_legal_terms=kwargs.get("accept_legal_terms", True)) self._authorization_code(code) @@ -216,7 +228,7 @@ def _default_headers(self): if (not self._token and self._refresh_token) or datetime.utcnow() >= self._expires: self._renew_token() if not self._token: - raise Exception("You need to login!") + raise MissingLogin("You need to login!") return { "Authorization": f"Bearer {self._token}", "App-Version": "999.99.9", diff --git a/lidlplus/exceptions.py b/lidlplus/exceptions.py index 7b44e50..9d6d814 100644 --- a/lidlplus/exceptions.py +++ b/lidlplus/exceptions.py @@ -13,3 +13,7 @@ class LoginError(Exception): class LegalTermsException(Exception): """Not accepted legal terms""" + + +class MissingLogin(Exception): + """Login necessary""" diff --git a/requirements.txt b/requirements.txt index c41fff0..903c4c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -getuseragent==0.0.7 -oic==1.4.0 -requests==2.28.1 -selenium-wire==5.1.0 -webdriver-manager==3.8.5 +getuseragent~=0.0.7 +oic~=1.6.0 +requests~=2.31.0 +selenium-wire~=5.1.0 +webdriver-manager~=3.8.6 diff --git a/setup.py b/setup.py index bef1db4..b7f8824 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="lidl-plus", - version="0.2.4", + version="0.2.5", author="Andre Basche", description="Fetch receipts and more from Lidl Plus", long_description=long_description, @@ -22,7 +22,7 @@ }, license="MIT", classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "License :: OSI Approved :: MIT License", "Natural Language :: English",