+# :copyright: Copyright (c) 2017 ftrack
+# This snippet was last tested with ftrack 3.5.2 and Python API 1.1.1
+logger = logging.getLogger(__file__)
+def print_header(title='', char='=', length=80, new_line=False):
+ '''Print formatted header.'''
+ num_chars_right = length - len(title) - 2
+ print char, title, num_chars_right*char
+def print_events(event):
+ '''Event callback printing all new or updated entities.'''
+ print_header('ftrack.update', new_line=True)
+ source = event['source']
+ for entity in event['data'].get('entities', []):
+ #TODO: Do something with the updated entities
+def register(session, **kw):
+ '''Register event listener.'''
+ # Validate that session is an instance of ftrack_api.Session. If not,
+ # assume that register is being called from an incompatible API
+ # and return without doing anything.
+ if not isinstance(session, ftrack_api.Session):
+ # Exit to avoid registering this plugin again.
+ # Register the event handler
+ session.event_hub.subscribe('topic=ftrack.update', print_events)
+ logger.info('Registered event handler')
+if __name__ == '__main__':
+ '''Register and wait for events when called as script'''
+ logging.basicConfig(level=logging.INFO)
+ logging.getLogger('ftrack_api').setLevel(level=logging.WARN)
+ logging.getLogger('requests').setLevel(level=logging.WARN)
+ session = ftrack_api.Session()
+ session.event_hub.wait()