"""Interface for the ows-lyrics microservice.""" from oto import response from owsrequest import request from sentry_sdk import capture_exception from product_workflow.constants import error, services def apply_track_lyrics(correction_details): """Call ows-lyrics to save lyrics correction value to original table. Args: correction_details: Returns: response.Response: json data or errors """ data = {'lyrics': correction_details['key_value']} try: ows_lyrics_response = request.put( services.OWS_LYRICS, '/tracks/{}/lyrics'.format(correction_details['key_id']), json=data) info_body = ows_lyrics_response.json() if ows_lyrics_response.status_code != 200: return response.create_error_response( status=ows_lyrics_response.status_code, code=info_body.get('code'), message=info_body.get('message')) return response.Response(message=info_body) except Exception: capture_exception() return response.create_error_response( status=500, code=error.INTERNAL_ERROR, message='Error while applying correction tracks ' 'lyrics in approval.') def get_lyrics_by_track_ids(track_ids): """Get lyrics of all tracks for a product. Args: track_ids (int): unique identifiers for the tracks Returns: response.Response: response object containing track lyrics data """ try: tuids = ','.join(map(str, track_ids)) ows_lyrics_response = request.get( services.OWS_LYRICS, '/tracks/lyrics?tuids=' + tuids) response_body = ows_lyrics_response.json() if ows_lyrics_response.status_code != 200: return response.create_error_response( status=ows_lyrics_response.status_code, code=response_body.get('code'), message=response_body.get('message')) return response.Response(message=response_body) except Exception: capture_exception() return response.create_error_response( status=500, code=error.INTERNAL_ERROR, message='Error while fetching lyrics by track ids')