Skip to content

Commit

Permalink
Implemented Issue #1 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpunkt committed Jul 17, 2020
1 parent e4722e3 commit 0268f2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions blocklenium/blocklenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

from blocklenium.selenium_worker import SeleniumWorker


logger = logging.getLogger(__name__)


class Blocklenium(object):
def __init__(self, config):

self.config = config
self.plc_start_flag = self.config['PLC_START_FLAG']

self.is_error = False

Expand All @@ -36,16 +34,21 @@ def __init__(self, config):

self.callback = self._plc.notification(pyads.
PLCTYPE_BOOL)(
self._callback)
self._callback)

def _callback(self, handle, name, timestamp, value):
if value:
logger.info('Queued flag to handle...')
logger.info(
'Callback received True, queuing True for worker...')
self.queue.put(True)
else:
logger.info(
'Callback received False, queuing None for worker...')
self.queue.put(None)

logger.debug(
'handle: {0} | name: {1} | timestamp: {2} | value: {3}'.format(
handle, name, timestamp, value))
'handle: {0} | name: {1} | timestamp: {2} | value: {3}'.
format(handle, name, timestamp, value))

def handle_error(self, message, error=None):
self.is_error = True
Expand Down Expand Up @@ -92,7 +95,7 @@ def start(self):
return

self._plc.add_device_notification(
self.plc_start_flag, attr,
self.config['PLC_START_FLAG'], attr,
self.callback)

while not self.is_error:
Expand Down
8 changes: 7 additions & 1 deletion blocklenium/selenium_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, queue, config):
self.js = f.read()

def run(self):
"""Runs in an endless loop until False was put on the queue.
If True is on the queue, opens a browser and runs bookmarklet.
If None is on the queue, closes the browser."""
logger.debug('Thread running.')

while True:
Expand Down Expand Up @@ -77,8 +80,11 @@ def run(self):
# Close browser
if self.chromedriver is not None:
self.chromedriver.quit()
self.chromedriver = None

break
if q is False:
logger.info('Exiting worker loop...')
break

def desk_login(self):
logger.info('attempting login to desk...')
Expand Down

0 comments on commit 0268f2a

Please sign in to comment.