"""Get marketing highlights information from ows-marketing microservice. Get marketing highlights info by calling the ows-marketing microservice. """ import json from oto import response from owsrequest import request from salessheets import config from salessheets.constants import field_const from salessheets.constants import ows_services from daemonJwtHandler import daemon_handler def get_marketing_highlights(entity_type, release_id): """Get marketing highlights info from ows-marketing microservice. Args: entity_type (str): type of entity. release_id (str): release id. Returns: Response: json containing marketing highlights info: {'items': [{ 'scope': 'example_scope', 'description': 'example_description', 'entity': 'example', 'entity_id': 1234567, 'client': 'example_client', 'mkt_program_id': 12345, 'attachment': 'example_attachment', 'highlight_id': 123456 }] } """ endpoint = '/highlights/{}/{}'.format(entity_type, release_id) authorization = daemon_handler.daemon_handler( ows_services.OWS_MARKETING_SERVICE_NAME) marketing_highlights_response = request.process( ows_services.APPLICATION_NAME, config.ENVIRONMENT, ows_services.SERVICE_CALL_METHOD_GET, ows_services.OWS_MARKETING_SERVICE_NAME, endpoint, authorization_header=authorization, isDaemon=True) message = json.loads( marketing_highlights_response.content.decode('utf8')) if marketing_highlights_response.status_code == 200: highlights_result = message['items'] return response.Response(message=highlights_result) return response.Response( errors=message, status=marketing_highlights_response.status_code) def filter_marketing_highlights(highlights, **conditions): """Filter marketing highlights by conditions. Args: highlights (list): list of dictionaries with highlights data. conditions (dict): keys and values for filtering highlights Returns: Response: message contains list of filtered product highlights """ product_highlights = [] for highlight in highlights: for key, value in conditions.items(): if (highlight[key] == value and highlight not in product_highlights and highlight[field_const.DESCRIPTION]): product_highlights.append(highlight) return product_highlights