def example_catalog_tree(): """Example CatalogTree""" print '\n--- example module cbs : CatalogTree ---\n' # create CatalogTree ct = CatalogTree(language = 'en') ct.set_feeds() # service document print 'Url service document:', ct.url print 'The service exposes {0} collections:'.format(len(ct.collections)) for i, collection in enumerate(ct.collections, 1): feed = ct.feeds[collection] print '-', collection, '->', len(feed.entries), 'entries' # methods print '\n--- example module cbs : CatalogTree - methods ---' # get theme_id for entry in ct.get_entries('Themes'): if entry['ParentID'] is not None and entry['Language']=='en' \ and ct.get_property('Themes', entry['ParentID'], 'ID', 'ParentID') is not None : theme_id = entry['ID'] break theme_title = ct.get_property(collection = 'Themes', entry_id = theme_id, primary_key = 'ID', property_name = 'Title') print 'Theme id = {0}, title = {1}.'.format(theme_id, theme_title) # get parents theme print "\n* method: get_parents -> ct.get_parents(theme_id = {0})".format(theme_id) parents = ct.get_parents(theme_id = theme_id) for parent_id in parents[:-1]: print '- {0} ({1})'.format(ct.get_property('Themes', parent_id, 'ID', 'Title'), parent_id) # get children theme print "\n* method: get_children -> ct.get_children(theme_id = {0})".format(theme_id) children = ct.get_children(theme_id) for child in children['Tables_Themes']: print '- Table: {0} (id: {1})'.format(ct.get_property('Tables', child['TableID'], 'ID', 'Title'), child['TableID']) for child in children['Themes']: print '- Theme: {0} (id: {1})'.format(ct.get_property('Themes', child['ID'], 'ID', 'Title'), child['ID'])