示例#1
0
def searches(from_,
             to,
             hashids=None,
             device=None,
             query_name=None,
             source=None,
             total_hits=None,
             tz=None,
             format_=None,
             **opts):
    """
    Return number of searches in a period grouped by date.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'device': device,
        'query_name': query_name,
        'source': source,
        'total_hits': total_hits,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/searches', query_params)
示例#2
0
def searches_top(from_,
                 to,
                 hashids=None,
                 device=None,
                 query_name=None,
                 exclude=None,
                 total_hits=None,
                 tz=None,
                 format_=None,
                 **opts):
    """
    Returns list of most common searches in a period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'device': device,
        'query_name': query_name,
        'exclude': exclude,
        'total_hits': total_hits,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/searches/top', query_params)
示例#3
0
def reindex_to_temp(hashid, name, **opts):
    params = {}
    if 'reset' in opts:
        params['reset'] = opts['reset']

    api_client = ManagementAPIClient(**opts)
    return api_client.post(_get_index_url(hashid, name) + '/_reindex_to_temp',
                           query_params=params)
示例#4
0
def create_temp(hashid, name, **opts):
    params = {}
    if 'destination_server' in opts:
        params['destination_server'] = opts['destination_server']

    api_client = ManagementAPIClient(**opts)
    return api_client.post(_get_index_url(hashid, name) + '/temp',
                           query_params=params)
示例#5
0
文件: items.py 项目: doofinder/pydoof
    def __init__(self, hashid, name, rpp=None, **opts):
        super(Scroll, self).__init__()

        self.scroll_id = None
        self.rpp = rpp

        self.hashid = hashid
        self.name = name

        self.api_client = ManagementAPIClient(**opts)
示例#6
0
文件: items.py 项目: doofinder/pydoof
class Scroll():
    @staticmethod
    def __get_url(hashid, name):
        return f'/api/v2/search_engines/{hashid}/indices/{name}/items/'

    def __init__(self, hashid, name, rpp=None, **opts):
        super(Scroll, self).__init__()

        self.scroll_id = None
        self.rpp = rpp

        self.hashid = hashid
        self.name = name

        self.api_client = ManagementAPIClient(**opts)

    def __iter__(self):
        scroll_page = self.new()
        while scroll_page['items']:
            for item in scroll_page['items']:
                yield item
            scroll_page = self.__next_with_retry()

    def __next_with_retry(self):
        tries = 0
        while True:
            try:
                return self.next()
            except TooManyRequestsError:
                if tries < 3:
                    tries += 1
                    sleep(1)
                else:
                    raise

    @property
    def _query_params(self):
        params = {}
        if self.scroll_id:
            params['scroll_id'] = self.scroll_id
        if self.rpp:
            params['rpp'] = self.rpp
        return params

    def new(self):
        scroll_page = self.api_client.get(
            self.__get_url(self.hashid, self.name), self._query_params)
        self.scroll_id = scroll_page['scroll_id']
        return scroll_page

    def next(self):
        return self.api_client.get(self.__get_url(self.hashid, self.name),
                                   self._query_params)
示例#7
0
def query_log_iter(from_, to, hashids=None, **opts):
    """
    Returns an iterator with all the queries done to the search API in a
    period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids
    })

    api_client = ManagementAPIClient(stream=True, **opts)
    return api_client.request('GET', '/api/v2/stats/query_log', query_params)
示例#8
0
def facets(from_, to, hashids=None, tz=None, format_=None, **opts):
    """
    Returns how many times facets filters have been used in a period, grouped
    by facet field name.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/facets', query_params)
示例#9
0
def inits(from_, to, hashids=None, device=None, tz=None, format_=None, **opts):
    """
    Returns number of total unique search sessions in a period group by date.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'device': device,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/inits', query_params)
示例#10
0
def sales(from_, to, hashids=None, tz=None, format_=None, **opts):
    """
    Returns the total price for sales checkouts in a period, where session_id
    identifies every sale.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/sales', query_params)
示例#11
0
def usage(from_, to, hashids=None, type_=None, format_=None, **opts):
    """
    Returns usage to search engines during a period.
    It sums the query and API requests made to the service.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'type': type_,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/usage', query_params)
示例#12
0
def facets_top(from_, to, hashids=None, tz=None, format_=None, **opts):
    """
    Returns most common facets filters used, how many times they have been
    used, and which filter has been applied in a period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/facets/top', query_params)
示例#13
0
    def test_can_set_per_request_host(self, requests_mock):
        response_mock = mock.Mock()
        response_mock.status_code = 200
        response_mock.text = 'OK'
        session_mock = mock.Mock()
        session_mock.request.return_value = response_mock
        requests_mock.Session.return_value = session_mock

        pydoof.management_url = 'https://eu1-api.doofinder.com'
        api_client = ManagementAPIClient(
            management_url='http://localhost:8000')
        api_client.request('GET', url='/')

        session_mock.request.assert_called_with('GET',
                                                url='http://localhost:8000/',
                                                params=mock.ANY,
                                                json=mock.ANY,
                                                headers=mock.ANY,
                                                auth=mock.ANY)
示例#14
0
def clicks(from_,
           to,
           hashids=None,
           device=None,
           tz=None,
           format_=None,
           **opts):
    """
    Returns number of times a user clicked an item in a period grouped by date.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'device': device,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/clicks', query_params)
示例#15
0
def redirects(from_,
              to,
              hashids=None,
              redirect_id=None,
              tz=None,
              format_=None,
              **opts):
    """
    Returns how many times users have been redirected by a custom redirections,
    and to which url in a period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'id': redirect_id,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/redirects', query_params)
示例#16
0
    def test_raise(self, status_code, error_code, expected_exception,
                   requests_mock):
        response_mock = mock.Mock()
        response_mock.status_code = status_code
        response_mock.json.return_value = {
            'error': {
                'code': error_code,
                'details': 'Details',
                'message': 'Message'
            }
        }
        session_mock = mock.Mock()
        session_mock.request.return_value = response_mock
        requests_mock.Session.return_value = session_mock

        api_client = ManagementAPIClient()
        with self.assertRaises(expected_exception) as cm:
            api_client.request('GET', url='/')

        self.assertEqual(cm.exception.details, 'Details')
        self.assertEqual(cm.exception.message, 'Message')
示例#17
0
def banners(from_,
            to,
            hashids=None,
            banner_id=None,
            tz=None,
            format_=None,
            **opts):
    """
    Returns how many times banners have been displayed and clicked in a period,
    grouped by banner id.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'id': banner_id,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/banners', query_params)
示例#18
0
def inits_locations(from_,
                    to,
                    hashids=None,
                    device=None,
                    tz=None,
                    format_=None,
                    **opts):
    """
    Returns all unique sessions geolocation(longituted and latitude pairs) for
    a period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'device': device,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/inits/locations', query_params)
示例#19
0
def clicked_items_searches(from_,
                           to,
                           dfid,
                           hashids=None,
                           device=None,
                           tz=None,
                           format_=None,
                           **opts):
    """
    Returns the most common searched for a clicked item, and how many times it
    has been clicked from those searches.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'dfid': dfid,
        'hashid': hashids,
        'device': device,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/clicked_items/searches', query_params)
示例#20
0
def clicked_items(from_,
                  to,
                  hashids=None,
                  query=None,
                  device=None,
                  limit=None,
                  tz=None,
                  format_=None,
                  **opts):
    """
    Returns most commonly clicked items in a period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids,
        'query': query,
        'device': device,
        'limit': limit,
        'tz': tz,
        'format': format_
    })
    api_client = ManagementAPIClient(**opts)
    return api_client.get('/api/v2/stats/clicked_items', query_params)
示例#21
0
def update(hashid, name, index, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.patch(_get_index_url(hashid, name), index)
示例#22
0
def delete_temp(hashid, name, **opts):
    api_client = ManagementAPIClient(**opts)
    api_client.delete(_get_index_url(hashid, name) + '/temp')
示例#23
0
def delete(hashid, **opts):
    api_client = ManagementAPIClient(**opts)
    api_client.delete(_get_searchengine_url(hashid))
示例#24
0
def create(hashid, index, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.post(_get_indices_url(hashid), index)
示例#25
0
def schedule_process(hashid, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.post(_get_process_url(hashid))
示例#26
0
def get_process_status(hashid, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.get(_get_process_url(hashid))
示例#27
0
def get_reindex_status(hashid, name, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.get(_get_index_url(hashid, name) + '/_reindex_to_temp')
示例#28
0
def get(hashid, name, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.get(_get_index_url(hashid, name))
示例#29
0
def replace_by_temp(hashid, name, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.post(_get_index_url(hashid, name) + '/_replace_by_temp')
示例#30
0
def list(hashid, **opts):
    api_client = ManagementAPIClient(**opts)
    return api_client.get(_get_indices_url(hashid))