From 0fbafd81e8d68b8171ac41436abe947850d0c340 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Tue, 20 Dec 2022 20:19:34 +0100 Subject: [PATCH] Change max line length from 88 to 120 --- .github/workflows/python-check.yml | 7 +++---- lidlplus/__main__.py | 30 +++++++----------------------- lidlplus/api.py | 22 +++++++--------------- setup.py | 4 +--- 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml index df6ceb3..d4a6f33 100644 --- a/.github/workflows/python-check.yml +++ b/.github/workflows/python-check.yml @@ -30,11 +30,10 @@ jobs: run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint --max-line-length 120 $(git ls-files '*.py') - name: Check black style run: | - black . --check + black . -l 120 --check diff --git a/lidlplus/__main__.py b/lidlplus/__main__.py index 891fc75..a3937f3 100755 --- a/lidlplus/__main__.py +++ b/lidlplus/__main__.py @@ -22,17 +22,11 @@ def get_arguments(): parser.add_argument("-l", "--language", help="language (de, be, nl, at, ...)") parser.add_argument("-u", "--user", help="Lidl Plus login user") parser.add_argument("-p", "--password", help="Lidl Plus login password") - parser.add_argument( - "--2fa", choices=["phone", "email"], default="phone", help="set 2fa method" - ) + parser.add_argument("--2fa", choices=["phone", "email"], default="phone", help="set 2fa method") parser.add_argument("-r", "--refresh-token", help="refresh token to authenticate") - subparser = parser.add_subparsers( - title="commands", metavar="command", required=True - ) + subparser = parser.add_subparsers(title="commands", metavar="command", required=True) auth = subparser.add_parser("auth", help="authenticate and get refresh_token") - auth.add_argument( - "auth", help="authenticate and get refresh_token", action="store_true" - ) + auth.add_argument("auth", help="authenticate and get refresh_token", action="store_true") receipt = subparser.add_parser("receipt", help="last receipt as json") receipt.add_argument("receipt", help="last receipt as json", action="store_true") receipt.add_argument("-a", "--all", help="fetch all receipts", action="store_true") @@ -62,21 +56,15 @@ def lidl_plus_login(args): country = args.get("country") or input("Enter your country (de, at, ...): ") if args.get("refresh_token"): return LidlPlusApi(language, country, args.get("refresh_token")) - username = args.get("username") or input( - "Enter your lidl plus username (phone number): " - ) + username = args.get("username") or input("Enter your lidl plus username (phone number): ") password = args.get("password") or getpass("Enter your lidl plus password: ") check_auth() lidl_plus = LidlPlusApi(language, country) try: text = f"Enter the verify code you received via {args['2fa']}: " - lidl_plus.login( - username, password, lambda: input(text), verify_mode=args["2fa"] - ) + lidl_plus.login(username, password, lambda: input(text), verify_mode=args["2fa"]) except WebBrowserException: - print( - "Can't connect to web browser. Please install Chrome, Chromium or Firefox" - ) + print("Can't connect to web browser. Please install Chrome, Chromium or Firefox") sys.exit(101) except LoginError: print("Login failed. Check your username and password") @@ -88,11 +76,7 @@ def print_refresh_token(args): """pretty print refresh token""" lidl_plus = lidl_plus_login(args) length = len(token := lidl_plus.refresh_token) - len("refresh token") - print( - f"{'-' * (length // 2)} refresh token {'-' * (length // 2 - 1)}\n" - f"{token}\n" - f"{'-' * len(token)}" - ) + print(f"{'-' * (length // 2)} refresh token {'-' * (length // 2 - 1)}\n" f"{token}\n" f"{'-' * len(token)}") def print_tickets(args): diff --git a/lidlplus/api.py b/lidlplus/api.py index 7a6085b..4733d8f 100644 --- a/lidlplus/api.py +++ b/lidlplus/api.py @@ -59,9 +59,7 @@ 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 - ) + client = Client(client_authn_method=CLIENT_AUTHN_METHOD, client_id=self._CLIENT_ID) client.provider_config(self._AUTH_API) code_challenge, self._code_verifier = client.add_code_challenge() args = { @@ -82,9 +80,7 @@ def _init_chrome(self, headless=True): if headless: options.add_argument("headless") options.add_experimental_option("mobileEmulation", {"userAgent": user_agent}) - return webdriver.Chrome( - service=ChromeService(ChromeDriverManager().install()), options=options - ) + return webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options) def _init_firefox(self, headless=True): @@ -153,16 +149,14 @@ def login(self, phone, password, verify_token_func, **kwargs): browser = self._get_browser(headless=kwargs.get("headless", True)) browser.get(self._register_link) wait = WebDriverWait(browser, 10) - is_visible = expected_conditions.visibility_of_element_located - is_clickable = expected_conditions.element_to_be_clickable - wait.until(is_visible((By.ID, "button_welcome_login"))).click() - wait.until(is_visible((By.NAME, "EmailOrPhone"))).send_keys(phone) + 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) browser.find_element(By.ID, "button_btn_submit_email").click() browser.find_element(By.ID, "button_btn_submit_email").click() try: - wait.until(is_clickable((By.ID, "field_Password"))).send_keys(password) + wait.until(expected_conditions.element_to_be_clickable((By.ID, "field_Password"))).send_keys(password) browser.find_element(By.ID, "button_submit").click() - element = wait.until(is_visible((By.CLASS_NAME, verify_mode))) + element = wait.until(expected_conditions.visibility_of_element_located((By.CLASS_NAME, verify_mode))) except TimeoutException as exc: raise LoginError("Wrong credentials") from exc element.find_element(By.TAG_NAME, "button").click() @@ -174,9 +168,7 @@ def login(self, phone, password, verify_token_func, **kwargs): self._authorization_code(code) def _default_headers(self): - if ( - not self._token and self._refresh_token - ) or datetime.utcnow() >= self._expires: + 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!") diff --git a/setup.py b/setup.py index 408868d..becb4b4 100644 --- a/setup.py +++ b/setup.py @@ -23,9 +23,7 @@ include_package_data=True, python_requires=">=3.8", install_requires=["requests"], - extras_require={ - "auth": ["selenium-wire", "webdriver-manager", "getuseragent", "oic"] - }, + extras_require={"auth": ["selenium-wire", "webdriver-manager", "getuseragent", "oic"]}, entry_points={ "console_scripts": [ "lidl-plus = lidlplus.__main__:start",