defprint_events(events):'''Print formated list of events.'''print'Events'print80*'='foreventinevents:printu'> {0}:{1} @ {2} by {3}: '.format(event['action'],event['insert'],event['created_at'],event['user']['username'])printevent['data']print80*'-'print80*'='print''# Attributes to preload for faster queryattributes=['action','insert','created_at','user.username','data']# Get all events given an entity ID:entity_id='73889d26-b066-11e6-9ce3-3c0754289fd3'events=session.query('select {0} from Event where parent_id is "{1}" order by created_at asc'.format(','.join(attributes),entity_id))print_events(events)# Get all events by a user during an interval:username='artist'start='2016-11-29T00:00:00'end='2016-12-30T00:00:00'events=session.query('select {0} from Event where user.username is "{1}" ''and created_at < "{2}" and created_at >= "{3}" ''order by created_at asc'.format(','.join(attributes),username,end,start))print_events(events)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.