"""Artists logic.""" import logging from models import ows_artist from utils import document as document_utils import util # noqa def prepare_doc(event): """Construct a Cloudsearch document for the artist_info corpus. Args: event (dict): event with artist data from Maxwell's Returns: dict: cloudsearch document ready for upload """ json_doc = {} doc_type = 'add' event_type = event.get('type') if not event_type or event.get('_metadata'): logging.warning( 'An event with incompatible format received: %s', event) return json_doc if event_type == 'delete': doc_type = 'delete' if doc_type == 'add': json_doc = ows_artist.get_artist_document( event['data']['artist_id']) return document_utils.prepare_for_upload( util.parse_spec_file('artists'), { 'type': doc_type, 'id': 'art{}'.format(event['data']['artist_id']), 'fields': json_doc})