示例#1
0
 def delete_review(self):
     u = f'{self.session.protocol}//{self.session.host}/services/reviews.php'
     p = {'identifier': self.identifier}
     a = S3Auth(self.session.access_key, self.session.secret_key)
     r = self.session.delete(u, params=p, auth=a)
     r.raise_for_status()
     return r
示例#2
0
    def __init__(self,
                 archive_session,
                 query,
                 fields=None,
                 sorts=None,
                 params=None,
                 full_text_search=None,
                 dsl_fts=None,
                 request_kwargs=None,
                 max_retries=None):
        params = params or {}

        self.session = archive_session
        self.dsl_fts = False if not dsl_fts else True
        if self.dsl_fts or full_text_search:
            self.fts = True
        else:
            self.fts = False
        self.query = query
        if self.fts and not self.dsl_fts:
            self.query = f'!L {self.query}'
        self.fields = fields or []
        self.sorts = sorts or []
        self.request_kwargs = request_kwargs or {}
        self._num_found = None
        self.fts_url = f'{self.session.protocol}//be-api.us.archive.org/ia-pub-fts-api'
        self.scrape_url = f'{self.session.protocol}//{self.session.host}/services/search/v1/scrape'
        self.search_url = f'{self.session.protocol}//{self.session.host}/advancedsearch.php'
        if self.session.access_key and self.session.secret_key:
            self.auth = S3Auth(self.session.access_key,
                               self.session.secret_key)
        else:
            self.auth = None
        self.max_retries = max_retries if max_retries is not None else 5

        # Initialize params.
        default_params = {'q': self.query}
        if 'page' not in params:
            if 'rows' in params:
                params['page'] = 1
            else:
                default_params['count'] = 10000
        else:
            default_params['output'] = 'json'
        # In the beta endpoint 'scope' was called 'index'.
        # Let's support both for a while.
        if 'index' in params:
            params['scope'] = params['index']
            del params['index']
        self.params = default_params.copy()
        self.params.update(params)

        # Set timeout.
        if 'timeout' not in self.request_kwargs:
            self.request_kwargs['timeout'] = 300

        # Set retries.
        self.session.mount_http_adapter(max_retries=self.max_retries)
示例#3
0
 def review(self, title, body, stars=None):
     u = f'{self.session.protocol}//{self.session.host}/services/reviews.php'
     p = {'identifier': self.identifier}
     d = {'title': title, 'body': body}
     if stars:
         d['stars'] = stars
     a = S3Auth(self.session.access_key, self.session.secret_key)
     r = self.session.post(u, params=p, data=json.dumps(d), auth=a)
     r.raise_for_status()
     return r
示例#4
0
 def review(self, title, body, stars=None):
     u = '{protocol}//{host}/services/reviews.php'.format(
         protocol=self.session.protocol, host=self.session.host)
     p = dict(identifier=self.identifier)
     d = dict(title=title, body=body)
     if stars:
         d['stars'] = stars
     a = S3Auth(self.session.access_key, self.session.secret_key)
     r = self.session.post(u, params=p, data=json.dumps(d), auth=a)
     r.raise_for_status()
     return r
示例#5
0
    def __init__(self, archive_session, query,
                 fields=None,
                 sorts=None,
                 params=None,
                 full_text_search=None,
                 request_kwargs=None,
                 max_retries=None):
        params = params or {}

        self.session = archive_session
        self.query = query
        self.fields = fields or list()
        self.sorts = sorts or list()
        self.request_kwargs = request_kwargs or dict()
        self._num_found = None
        self.fts = False if not full_text_search else True
        self.fts_url = '{0}//be-api.us.archive.org/fts/v1/search'.format(
            self.session.protocol)
        self.scrape_url = '{0}//{1}/services/search/v1/scrape'.format(
            self.session.protocol, self.session.host)
        self.search_url = '{0}//{1}/advancedsearch.php'.format(
            self.session.protocol, self.session.host)
        if self.session.access_key and self.session.secret_key:
            self.auth = S3Auth(self.session.access_key, self.session.secret_key)
        else:
            self.auth = None
        self.max_retries = max_retries if max_retries is not None else 5

        # Initialize params.
        default_params = dict(q=query)
        if 'page' not in params:
            default_params['count'] = 10000
        else:
            default_params['output'] = 'json'
        # In the beta endpoint 'scope' was called 'index'.
        # Let's support both for a while.
        if 'index' in params:
            params['scope'] = params['index']
            del params['index']
        self.params = default_params.copy()
        self.params.update(params)

        # Set timeout.
        if 'timeout' not in self.request_kwargs:
            self.request_kwargs['timeout'] = 300

        # Set retries.
        self.session.mount_http_adapter(max_retries=self.max_retries)
示例#6
0
    def __init__(self,
                 archive_session,
                 query,
                 fields=None,
                 sorts=None,
                 params=None,
                 request_kwargs=None):
        params = params or {}

        self.session = archive_session
        self.query = query
        self.fields = fields or list()
        self.sorts = sorts or list()
        self.request_kwargs = request_kwargs or dict()
        self._num_found = None
        self.scrape_url = '{0}//archive.org/services/search/v1/scrape'.format(
            self.session.protocol)
        self.search_url = '{0}//archive.org/advancedsearch.php'.format(
            self.session.protocol)
        self.auth = S3Auth(self.session.access_key, self.session.secret_key)

        # Initialize params.
        default_params = dict(q=query, REQUIRE_AUTH='true')
        if 'page' not in params:
            default_params['count'] = 10000
        else:
            default_params['output'] = 'json'
        # In the beta endpoint 'scope' was called 'index'.
        # Let's support both for a while.
        if 'index' in params:
            params['scope'] = params['index']
            del params['index']
        self.params = default_params.copy()
        self.params.update(params)

        # Set timeout.
        if 'timeout' not in self.request_kwargs:
            self.request_kwargs['timeout'] = 12

        # Set retries.
        self.session._mount_http_adapter(max_retries=5)