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