Files
edx-platform/scripts/show_events.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

39 lines
810 B
Python

"""
Show Event outputs.
"""
import json
import sys
import traceback
try:
import dateutil.parser
except ImportError:
def date_string(ds, fmt=''):
return ds
else:
def date_string(ds, fmt='%Y-%m-%d %H:%M:%S.%f'):
d = dateutil.parser.parse(ds).astimezone(dateutil.tz.tzutc())
return d.strftime(fmt)
def display(message):
print('{} - {}'.format(date_string(message['time']), message['event_type']))
if message.get('event'):
event = json.loads(message['event'])
for k in sorted(event):
print('\t{}: {}'.format(k, event[k]))
print()
while 1:
line = sys.stdin.readline()
if not line:
break
try:
obj = json.loads(line)
display(obj)
except Exception:
traceback.print_exc()
continue