summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2017-12-19 09:14:43 +0100
committerLars-Dominik Braun <lars@6xq.net>2017-12-19 09:14:43 +0100
commit8e939f8922815bd917f4dd750aa5f8a17a8f750c (patch)
treef30d630a33c1aba991b723da4fcb139852bac674 /contrib
parent6a771cf9df0e9446feab59b50cea2998d42a459f (diff)
downloadcrocoite-8e939f8922815bd917f4dd750aa5f8a17a8f750c.tar.gz
crocoite-8e939f8922815bd917f4dd750aa5f8a17a8f750c.tar.bz2
crocoite-8e939f8922815bd917f4dd750aa5f8a17a8f750c.zip
Select default behavior scripts by site URL
Diffstat (limited to 'contrib')
-rw-r--r--contrib/celerycrocoite.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/contrib/celerycrocoite.py b/contrib/celerycrocoite.py
index 8fab046..ede58be 100644
--- a/contrib/celerycrocoite.py
+++ b/contrib/celerycrocoite.py
@@ -29,6 +29,19 @@ import celery
from urllib.parse import urlsplit
import crocoite.cli
+from crocoite import behavior
+
+def prettyTimeDelta (seconds):
+ """
+ Pretty-print seconds to human readable string 1d 1h 1m 1s
+ """
+ seconds = int(seconds)
+ days, seconds = divmod(seconds, 86400)
+ hours, seconds = divmod(seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ s = [(days, 'd'), (hours, 'h'), (minutes, 'm'), (seconds, 's')]
+ s = filter (lambda x: x[0] != 0, s)
+ return ' '.join (map (lambda x: '{}{}'.format (*x), s))
def setup (bot):
m = bot.memory['crocoite'] = SopelMemory ()
@@ -62,7 +75,7 @@ def archive (bot, trigger):
args = {
'url': url,
'output': None,
- 'onload': ['scroll.js'],
+ 'onload': ['scroll.js'] + behavior.getByUrl (url),
'onsnapshot': [],
'browser': None,
'logBuffer': 1000,
@@ -80,7 +93,16 @@ def archive (bot, trigger):
# XXX: for some reason we cannot access the job’s state through handle,
# instead use a callback quirk
j = jobs[handle.id] = {'handle': handle, 'trigger': trigger, 'state': {}}
- bot.reply ('{} has been queued as {}'.format (url, handle.id))
+
+ # pretty-print a few selected args
+ showargs = {
+ 'onload': ','.join (args['onload']),
+ 'idleTimeout': prettyTimeDelta (args['idleTimeout']),
+ 'timeout': prettyTimeDelta (args['timeout']),
+ }
+ strargs = ', '.join (map (lambda x: '{}={}'.format (*x), showargs.items ()))
+ bot.reply ('{} has been queued as {} with {}'.format (url, handle.id, strargs))
+
try:
result = handle.get (on_message=lambda x: updateState (j, x))
bot.reply ('{} ({}) finished'.format (url, handle.id))