"""Utilities for reading switchboard graphql json data.""" from glom import glom def get_label_name(swb_json): """Get the name of the Orchard label (vendor).""" try: return swb_json.get('labelAccount', {}).get('name') except AttributeError: return None def get_product_artist_name(swb_json): """Get the name of the artist on a product.""" try: return swb_json.get('displayArtist', {}).get('name') except AttributeError: return None def get_product_title(swb_json): """Get the name of the title of a product.""" try: return swb_json.get('formalTitle', {}).get('titleText') except AttributeError: return None def get_deal_name(swb_json): """Get the switchboard deal name.""" return glom(swb_json, 'switchboardExtensions.governingDeal.name', default='') def get_maintenance_owner_name(swb_json): """Get maintenance owner name.""" return glom(swb_json, 'maintenanceOwner.name', default='')