"""Rename Artist via GraphQL.""" import argparse from connectors.graphql import GraphQLBackoffConnector from constants import graphql_queries import config # create GraphQL connector graphql_conn = GraphQLBackoffConnector(config.GRAPHQL_GATEWAY_URL, config.APPLICATION_NAME) graphql_conn.set_headers({ 'Orchard-Profile-Type': config.ORCHARD_PROFILE_TYPE, 'Orchard-Profile-Id': config.ORCHARD_PROFILE_ID, 'Orchard-Identity-Id': config.ORCHARD_IDENTITY_ID, 'Orchard-Roles': config.ORCHARD_ROLES, 'Orchard-User-Id': config.OA_USER, }) def rename_artist(artist_id, artist_name, request_type, current_artist_id, logger): response = None if request_type == 'merge' and current_artist_id: response = graphql_conn.execute( graphql_queries.merge_artist, { 'artistId': artist_id, 'artistName': artist_name, 'requestType': request_type, 'currentArtistId': current_artist_id } ) elif request_type == 'rename': response = graphql_conn.execute( graphql_queries.rename_artist, { 'artistId': artist_id, 'artistName': artist_name } ) else: raise Exception("Current Artist ID is required for a merge request") msg = 'GraphQL Call Completed - Artist Id {} renamed.'.format(artist_id) logger.info(msg) return response def main(correlation_id=None): logger = config.get_current_logger(correlation_id) logger.info('Running script to rename an artist') print('Running script to rename an artist') parser = argparse.ArgumentParser() parser.add_argument('--artist_id', type=int, default=None) parser.add_argument('--artist_name', type=str, default=None) parser.add_argument('--request_type', type=str, default='rename') parser.add_argument('--current_artist_id', type=int, default=None) args = parser.parse_args() artist_id = int(args.artist_id) artist_name = str(args.artist_name) request_type = str(args.request_type) current_artist_id =\ int(args.current_artist_id) if args.current_artist_id else None response = rename_artist(artist_id, artist_name, request_type, current_artist_id, logger) logger.info(response) logger.info('Completed execution of script to rename an artist') print('Completed execution of script to rename an artist') if __name__ == '__main__': main()