<commit_before>"""
Created on 6 Nov 2017

@author: <NAME> (<EMAIL>)

https://xy1eszuu23.execute-api.us-west-2.amazonaws.com/staging/topicMessages?
topic=south-coast-science-dev/production-test/loc/1/gases&startTime=2018-03-31T10:45:50Z&endTime=2018-03-31T10:46:50Z
"""

from scs_core.aws.client.rest_client import RESTClient
from scs_core.aws.data.message import MessageCollection


# --------------------------------------------------------------------------------------------------------------------

class MessageManager(object):
    """
    classdocs
    """

    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, http_client, api_key, verbose=False):
        """
        Constructor
        """
        self.__rest_client = RESTClient(http_client, api_key)
        self.__verbose = verbose


    # ----------------------------------------------------------------------------------------------------------------

    def find_for_topic(self, topic, start_date, end_date):
        request_path = '/' + topic + '/' + start_date.utc().as_iso8601() + '/' + end_date.utc().as_iso8601()

        # request...
        self.__rest_client.connect()

        try:
            jdict = self.__rest_client.get(request_path)

            # messages...
            collection = MessageCollection.construct_from_jdict(jdict)

            messages = collection.items
        finally:
            self.__rest_client.close()<commit_msg>Robustified MessageManager against null collections.<commit_after>"""
Created on 6 Nov 2017

@author: <NAME> (<EMAIL>)

https://xy1eszuu23.execute-api.us-west-2.amazonaws.com/staging/topicMessages?
topic=south-coast-science-dev/production-test/loc/1/gases&startTime=2018-03-31T10:45:50Z&endTime=2018-03-31T10:46:50Z
"""

from scs_core.aws.client.rest_client import RESTClient
from scs_core.aws.data.message import MessageCollection


# --------------------------------------------------------------------------------------------------------------------

class MessageManager(object):
    """
    classdocs
    """

    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, http_client, api_key, verbose=False):
        """
        Constructor
        """
        self.__rest_client = RESTClient(http_client, api_key)
        self.__verbose = verbose


    # ----------------------------------------------------------------------------------------------------------------

    def find_for_topic(self, topic, start_date, end_date):
        request_path = '/' + topic + '/' + start_date.utc().as_iso8601() + '/' + end_date.utc().as_iso8601()

        # request...
        self.__rest_client.connect()

        try:
            jdict = self.__rest_client.get(request_path)

            # messages...
            collection = MessageCollection.construct_from_jdict(jdict)

            messages = [] if collection is None else collection.items

        finally:
            self.__rest_client.close()
{'fraction_non_alphanumeric': 0.3187702265372168, 'fraction_numerical': 0.02977346278317152, 'mean_word_length': 1.3363567649281936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3423457', 'n_tokens_mistral': 853, 'n_tokens_neox': 769, 'n_words': 116}