Functioning check_in/check_out.
This commit is contained in:
parent
5fa48bc299
commit
c4ac8f96f9
|
@ -10,6 +10,7 @@ import logging
|
|||
import os
|
||||
import time
|
||||
import typing as T
|
||||
from urllib.parse import urlparse
|
||||
|
||||
os.environ['PATH'] = os.environ['PATH'] + \
|
||||
':' + os.path.join(os.path.abspath(os.path.curdir), 'bin')
|
||||
|
@ -32,6 +33,8 @@ def safely(f: T.Callable) -> T.Callable:
|
|||
f(self, *args, **kwargs)
|
||||
except WebDriverException as e:
|
||||
self.logger.error("Something went wrong: %s", e)
|
||||
finally:
|
||||
self.switch_to.default_content()
|
||||
|
||||
return _protection
|
||||
|
||||
|
@ -91,6 +94,7 @@ class Operator(wd.Firefox):
|
|||
|
||||
self.debug = debug
|
||||
self.base_uri = base_uri
|
||||
self.uri = urlparse(base_uri)
|
||||
self.timeout = timedelta(seconds=timeout)
|
||||
|
||||
if proxy:
|
||||
|
@ -101,6 +105,7 @@ class Operator(wd.Firefox):
|
|||
self.profile.set_preference('network.proxy.ssl_port', proxy[1])
|
||||
|
||||
super().__init__(firefox_profile=self.profile, options=self.opts, *args, **kwargs)
|
||||
self.fullscreen_window()
|
||||
|
||||
self.z_name = name if name is not None else __name__
|
||||
self.logger = logging.getLogger("{}.{}".format(__name__, self.name))
|
||||
|
@ -183,26 +188,34 @@ class Operator(wd.Firefox):
|
|||
else:
|
||||
self.logger.warning("Logout failed: %s", user)
|
||||
|
||||
def logged_in(self):
|
||||
@property
|
||||
def logged_in(self) -> bool:
|
||||
"""
|
||||
Check if already logged in. Checks if page is '/jsp/home.jsp'
|
||||
and if login cookie is set (and not expired).
|
||||
"""
|
||||
pass
|
||||
_base_domain = '.'.join(self.uri.netloc.split('.')[-2:])
|
||||
cookies = [c['name'] for c in self.get_cookies() if _base_domain in c['domain']]
|
||||
_right_url = "/jsp/home.jsp" in self.current_url
|
||||
_cookies = "dtLatC" in cookies
|
||||
return _right_url and _cookies
|
||||
|
||||
@safely
|
||||
def check_in(self, force: bool=False) -> None:
|
||||
"""
|
||||
Click the check in button.
|
||||
"""
|
||||
# TODO: Check if the page displays you're already
|
||||
# checked in.
|
||||
if not force and not self.logged_in:
|
||||
self.logger.warning("Not logged in!")
|
||||
return
|
||||
if self._checked_in:
|
||||
self.logger.warn("Already logged in!")
|
||||
self.logger.warn("Already checked in!")
|
||||
if not force:
|
||||
return
|
||||
iframe = self.find_element_by_xpath('//iframe[contains(@id, "gsmd_container.jsp")]')
|
||||
self.switch_to.frame(iframe)
|
||||
enter_butt = self.find_element_by_xpath('//input[@value="Entrata"]')
|
||||
enter_butt.submit()
|
||||
enter_butt.click()
|
||||
# Click the check in button and change
|
||||
# self._checked_in state in case of success
|
||||
pass
|
||||
|
@ -212,14 +225,17 @@ class Operator(wd.Firefox):
|
|||
"""
|
||||
Click the check out button.
|
||||
"""
|
||||
# TODO: Check if the page displays you're already
|
||||
# checked out.
|
||||
if not force and not self.logged_in:
|
||||
self.logger.warning("Not logged in!")
|
||||
return
|
||||
if not self._checked_in:
|
||||
self.logger.warn("Not yet logged in!")
|
||||
self.logger.warn("Not yet checked in!")
|
||||
if not force:
|
||||
return
|
||||
iframe = self.find_element_by_xpath('//iframe[contains(@id, "gsmd_container.jsp")]')
|
||||
self.switch_to.frame(iframe)
|
||||
exit_butt = self.find_element_by_xpath('//input[@value="Uscita"]')
|
||||
exit_butt.submit()
|
||||
exit_butt.click()
|
||||
# Click the check in button and change
|
||||
# self._checked_in state in case of success
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user