Skip to content

Commit

Permalink
Fix checks, bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 24, 2023
1 parent 55b70f3 commit dc091a2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
13 changes: 11 additions & 2 deletions lidlplus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 18 additions & 6 deletions lidlplus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions lidlplus/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ class LoginError(Exception):

class LegalTermsException(Exception):
"""Not accepted legal terms"""


class MissingLogin(Exception):
"""Login necessary"""
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down

0 comments on commit dc091a2

Please sign in to comment.