Skip to content

Commit

Permalink
Change max line length from 88 to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Dec 20, 2022
1 parent 022569a commit 0fbafd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/python-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 7 additions & 23 deletions lidlplus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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):
Expand Down
22 changes: 7 additions & 15 deletions lidlplus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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):

Expand Down Expand Up @@ -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()
Expand All @@ -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!")
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0fbafd8

Please sign in to comment.