def active_entities(klass, account, start_time, end_time, **kwargs):
        """
        Returns the details about which entities' analytics metrics
        have changed in a given time period.
        """
        entity = kwargs.get('entity') or klass.ANALYTICS_MAP[klass.__name__]
        if entity == klass.ANALYTICS_MAP['OrganicTweet']:
            raise ValueError(
                "'OrganicTweet' not support with 'active_entities'")

        # The start and end times must be expressed in whole hours
        validate_whole_hours(start_time)
        validate_whole_hours(end_time)

        params = {
            'entity': entity,
            'start_time': to_time(start_time, None),
            'end_time': to_time(end_time, None)
        }
        params.update(kwargs)

        resource = klass.RESOURCE_ACTIVE_ENTITIES.format(account_id=account.id)
        response = Request(account.client, 'get', resource,
                           params=params).perform()
        return response.body['data']
Example #2
0
    def active_entities(klass, account, start_time, end_time, **kwargs):
        """
        Returns the details about which entities' analytics metrics
        have changed in a given time period.
        """
        entity_type = klass.__name__
        if entity_type == 'OrganicTweet':
            raise ValueError("'OrganicTweet' not support with 'active_entities'")

        # The start and end times must be expressed in whole hours
        validate_whole_hours(start_time)
        validate_whole_hours(end_time)

        params = {
            'entity': klass.ANALYTICS_MAP[entity_type],
            'start_time': to_time(start_time, None),
            'end_time': to_time(end_time, None)
        }

        for k in kwargs:
            if isinstance(kwargs[k], list):
                params[k] = ','.join(map(str, kwargs[k]))
            else:
                params[k] = kwargs[k]

        resource = klass.RESOURCE_ACTIVE_ENTITIES.format(account_id=account.id)
        response = Request(account.client, 'get', resource, params=params).perform()
        return response.body['data']
    def active_entities(klass, account, start_time, end_time, **kwargs):
        entity_type = klass.__name__
        if entity_type == 'OrganicTweet':
            raise ValueError("'OrganicTweet' not support with 'active_entities'")

        # The start and end times must be expressed in whole hours
        validate_whole_hours(start_time)
        validate_whole_hours(end_time)

        params = {
            'entity': klass.ANALYTICS_MAP[entity_type],
            'start_time': to_time(start_time, None),
            'end_time': to_time(end_time, None)
        }

        resource = klass.RESOURCE_ACTIVE_ENTITIES.format(account_id=account.id)
        response = Request(account.client, 'get', resource, params=params).perform()
        return response.body['data']
Example #4
0
    def active_entities(klass, account, start_time, end_time, **kwargs):
        entity_type = klass.__name__
        if entity_type == 'OrganicTweet':
            raise ValueError(
                "'OrganicTweet' not support with 'active_entities'")

        # The start and end times must be expressed in whole hours
        validate_whole_hours(start_time)
        validate_whole_hours(end_time)

        params = {
            'entity': klass.ANALYTICS_MAP[entity_type],
            'start_time': to_time(start_time, None),
            'end_time': to_time(end_time, None)
        }

        resource = klass.RESOURCE_ACTIVE_ENTITIES.format(account_id=account.id)
        response = Request(account.client, 'get', resource,
                           params=params).perform()
        return response.body['data']
    def _standard_params(klass, ids, metric_groups, **kwargs):
        """
        Sets the standard params for a stats request
        """
        end_time = kwargs.get('end_time', datetime.utcnow())
        start_time = kwargs.get('start_time', end_time - timedelta(seconds=604800))
        granularity = kwargs.get('granularity', GRANULARITY.HOUR)
        placement = kwargs.get('placement', PLACEMENT.ALL_ON_TWITTER)

        params = {
            'metric_groups': ','.join(metric_groups),
            'start_time': to_time(start_time, granularity),
            'end_time': to_time(end_time, granularity),
            'granularity': granularity.upper(),
            'entity': klass.ANALYTICS_MAP[klass.__name__],
            'placement': placement
        }

        params['entity_ids'] = ','.join(ids)

        return params
Example #6
0
    def _standard_params(klass, ids, metric_groups, **kwargs):
        """
        Sets the standard params for a stats request
        """
        end_time = kwargs.get('end_time', datetime.utcnow())
        start_time = kwargs.get('start_time', end_time - timedelta(seconds=604800))
        granularity = kwargs.get('granularity', GRANULARITY.HOUR)
        placement = kwargs.get('placement', PLACEMENT.ALL_ON_TWITTER)

        params = {
            'metric_groups': ','.join(metric_groups),
            'start_time': to_time(start_time, granularity),
            'end_time': to_time(end_time, granularity),
            'granularity': granularity.upper(),
            'entity': klass.ANALYTICS_MAP[klass.__name__],
            'placement': placement
        }

        params['entity_ids'] = ','.join(ids)

        return params
    def all_stats(klass, account, ids, metrics, **kwargs):
        """
        Pulls a list of metrics for a specified set of object IDs.
        """
        end_time = kwargs.get('end_time', datetime.datetime.utcnow())
        start_time = kwargs.get('start_time', end_time - datetime.timedelta(seconds=604800))
        granularity = kwargs.get('granularity', GRANULARITY.HOUR)
        segmentation_type = kwargs.get('segmentation_type', None)

        params = {
            'metrics': ','.join(metrics),
            'start_time': to_time(start_time, granularity),
            'end_time': to_time(end_time, granularity),
            'granularity': granularity.upper()
        }
        if segmentation_type is not None:
            params['segmentation_type'] = segmentation_type.upper()

        params[klass.ANALYTICS_MAP[klass.__name__]] = ','.join(ids)

        resource = klass.RESOURCE_STATS.format(account_id=account.id)
        response = Request(account.client, 'get', resource, params=params).perform()
        return response.body['data']
    def all_stats(klass, account, ids, metrics, **kwargs):
        """
        Pulls a list of metrics for a specified set of object IDs.
        """
        end_time = kwargs.get('end_time', datetime.utcnow())
        start_time = kwargs.get('start_time', end_time - timedelta(seconds=604800))
        granularity = kwargs.get('granularity', GRANULARITY.HOUR)
        segmentation_type = kwargs.get('segmentation_type', None)

        params = {
            'metrics': ','.join(metrics),
            'start_time': to_time(start_time, granularity),
            'end_time': to_time(end_time, granularity),
            'granularity': granularity.upper()
        }
        if segmentation_type is not None:
            params['segmentation_type'] = segmentation_type.upper()

        params[klass.ANALYTICS_MAP[klass.__name__]] = ','.join(ids)

        resource = klass.RESOURCE_STATS.format(account_id=account.id)
        response = Request(account.client, 'get', resource, params=params).perform()
        return response.body['data']
def test_to_time_based_on_granularity():
    for g in [None, GRANULARITY.HOUR, GRANULARITY.TOTAL]:
        assert to_time(t, g) == '2006-03-21T00:00:00Z'
    assert to_time(t, GRANULARITY.DAY) == '2006-03-21'
def test_to_time_based_on_granularity():
    for g in [None, GRANULARITY.HOUR, GRANULARITY.TOTAL]:
        assert to_time(t, g) == '2006-03-21T00:00:00Z'
    assert to_time(t, GRANULARITY.DAY) == '2006-03-21'