Snippets

ftrack API Example - working with Events

You are viewing an old version of this snippet. View the current version.
Revised by Lucas Correia 7d2f30f
def print_events(events):
    '''Print formated list of events.'''
    print 'Events'
    print 80*'='
    for event in events:
        print u'> {0}:{1} @ {2} by {3}: '.format(
            event['action'], event['insert'], event['created_at'], event['user']['username']
        )
        print event['data']
        print 80*'-'
    print 80*'='
    print ''


# Attributes to preload for faster query
attributes = ['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)


HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.