summaryrefslogtreecommitdiff
path: root/contrib/celerycrocoite.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2017-12-22 17:43:52 +0100
committerLars-Dominik Braun <lars@6xq.net>2017-12-22 17:43:52 +0100
commitfd279ff3168c91be2ed8a012af6395034475ccf5 (patch)
treef4a8b55db5f158a4be4cf8c48aa82d944c206595 /contrib/celerycrocoite.py
parentbcfbdd9b45b7e872ee77e1366197443d855d8c7c (diff)
downloadcrocoite-fd279ff3168c91be2ed8a012af6395034475ccf5.tar.gz
crocoite-fd279ff3168c91be2ed8a012af6395034475ccf5.tar.bz2
crocoite-fd279ff3168c91be2ed8a012af6395034475ccf5.zip
Add simple stats-keeping SiteLoader
Diffstat (limited to 'contrib/celerycrocoite.py')
-rw-r--r--contrib/celerycrocoite.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/celerycrocoite.py b/contrib/celerycrocoite.py
index ede58be..83be7a6 100644
--- a/contrib/celerycrocoite.py
+++ b/contrib/celerycrocoite.py
@@ -43,6 +43,16 @@ def prettyTimeDelta (seconds):
s = filter (lambda x: x[0] != 0, s)
return ' '.join (map (lambda x: '{}{}'.format (*x), s))
+def prettyBytes (b):
+ """
+ Pretty-print bytes
+ """
+ prefixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
+ while b >= 1024 and len (prefixes) > 1:
+ b /= 1024
+ prefixes.pop (0)
+ return '{:.1f} {}'.format (b, prefixes[0])
+
def setup (bot):
m = bot.memory['crocoite'] = SopelMemory ()
m['jobs'] = {}
@@ -105,7 +115,10 @@ def archive (bot, trigger):
try:
result = handle.get (on_message=lambda x: updateState (j, x))
- bot.reply ('{} ({}) finished'.format (url, handle.id))
+ stats = result['stats']
+ bot.reply ('{} ({}) finished. {} requests, {} failed, {} received.'.format (url,
+ handle.id, stats['requests'], stats['failed'],
+ prettyBytes (stats['bytesRcv'])))
except Exception as e:
# json serialization does not work well with exceptions. If their class
# names are unique we can still distinguish them.