From d4951d1fe8be0941df9cafbfe57c21d26f66e8ee Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 24 Dec 2017 10:23:09 +0100 Subject: Refactor behavior scripts No functional changes, just cleanup. Replaces onload and onsnapshot events. Move screen metric emulation, DOM snapshots and screenshots here as well. --- contrib/celerycrocoite.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'contrib/celerycrocoite.py') diff --git a/contrib/celerycrocoite.py b/contrib/celerycrocoite.py index 83be7a6..1923629 100644 --- a/contrib/celerycrocoite.py +++ b/contrib/celerycrocoite.py @@ -28,8 +28,7 @@ from sopel.tools import Identifier, SopelMemory import celery from urllib.parse import urlsplit -import crocoite.cli -from crocoite import behavior +from crocoite import behavior, cli def prettyTimeDelta (seconds): """ @@ -82,22 +81,19 @@ def archive (bot, trigger): bot.reply ('{} is not a valid URL'.format (url)) return + blacklistedBehavior = {'domSnapshot', 'screenshot'} args = { 'url': url, 'output': None, - 'onload': ['scroll.js'] + behavior.getByUrl (url), - 'onsnapshot': [], + 'enabledBehaviorNames': list (behavior.availableNames-blacklistedBehavior), 'browser': None, 'logBuffer': 1000, 'maxBodySize': 10*1024*1024, 'idleTimeout': 10, - # 1 hour - 'timeout': 1*60*60, - 'domSnapshot': False, - 'screenshot': False, + 'timeout': 1*60*60, # 1 hour } - handle = crocoite.cli.archive.delay (**args) + handle = cli.archive.delay (**args) m = bot.memory['crocoite'] jobs = m['jobs'] # XXX: for some reason we cannot access the job’s state through handle, @@ -106,9 +102,10 @@ def archive (bot, trigger): # pretty-print a few selected args showargs = { - 'onload': ','.join (args['onload']), + 'behavior': ','.join (args['enabledBehaviorNames']), 'idleTimeout': prettyTimeDelta (args['idleTimeout']), 'timeout': prettyTimeDelta (args['timeout']), + 'maxBodySize': prettyBytes (args['maxBodySize']), } strargs = ', '.join (map (lambda x: '{}={}'.format (*x), showargs.items ())) bot.reply ('{} has been queued as {} with {}'.format (url, handle.id, strargs)) -- cgit v1.2.3