add a little logging

This commit is contained in:
Noah Levitt 2014-02-14 15:18:10 -08:00
parent 2368688fbe
commit 28282641f2

View File

@ -1,13 +1,19 @@
# vim: set sw=4 et:
from json import dumps, load
from time import sleep
import os, re
import logging
behaviors_file = os.path.sep.join(__file__.split(os.path.sep)[:-1] + ['behaviors.json'])
def execute(url, ws, command_id):
def execute(url, websock, command_id):
logger = logging.getLogger('behaviors')
sleep(5)
with open(behaviors_file) as js:
behaviors = load(js)
for behavior in behaviors:
if re.match(behavior['site'], url):
for script in behavior['scripts']:
ws.send(dumps(dict(method="Runtime.evaluate", params={"expression": script}, id=next(command_id))))
msg = dumps(dict(method="Runtime.evaluate", params={"expression": script}, id=next(command_id)))
logger.debug('sending message to {}: {}'.format(websock, msg))
websock.send(msg)