Snippets

ftrack API Example - working with Events

Created by Lucas Correia last modified
'''Examples showing how to query `Event`s in ftrack.'''

# Attributes to preload for faster query
attributes = ['action', 'insert', 'created_at', 'user.username', 'data']

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 ''



# 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)



# Find all deletions that occurred today (server time)
import datetime
date = datetime.datetime.utcnow().date()
events = session.query(
    'select {0} from Event where created_at > "{1}" '
    'and insert is "delete" '
    'order by created_at asc'.format(
        ','.join(attributes), date
    )
)
print_events(events)

Comments (0)