brozzler/umbra/behaviors.py

14 lines
523 B
Python
Raw Normal View History

2014-02-13 01:00:39 -05:00
from json import dumps, load
from time import sleep
import os, re
behaviors_file = os.path.sep.join(__file__.split(os.path.sep)[:-1] + ['behaviors.json'])
def execute(url, ws, command_id):
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))))