Example #1
0
 def _validate_collection_name(self, collection):
     """  Change white spaces to underscores and upper case to lower case
     """
     if collection is None:
         return
     c = self.white_space_pattern.sub('_', collection)
     # check is collection is not a ISBN number, like 084930315X
     if not is_isbn_code(c):
         c = c.lower()  # Change it to lower case
     return c
Example #2
0
    def _remote_request_data(self, keyword):
        """ Get all the data from the requested keyword
            You can make a keyword like this:
                author: Richard Rowland
                subject: mechanism
            A keyword without ':' key means that you want to use "all the collections"
            URL to search any book
        """
        def _calculate_kwargs(keyword):
            """ Check if the keyword is like:
                book: Harry Potter && query: True && index: author_name
            """
            kwargs = {}
            queries = keyword.split('&&')
            for query in queries:
                fields = query.split(':')
                # If keyword is like, "subject: maths", etc.
                if len(fields) == 2:
                    _collection = fields[0].lower().strip()
                    _keyword = fields[1].strip()
                    if _collection in COLLECTIONS or _collection in QUERIES:
                        kwargs[_collection] = _keyword
                    else:
                        raise TaricGeneralException(
                            "This collection or query does not exist %s" %
                            _collection)
            _q = kwargs.get('query')
            if _q:
                if _q == 'True' or _q == 'true':
                    kwargs['query'] = True
                else:
                    kwargs['query'] = False
            return kwargs

        kwargs = _calculate_kwargs(keyword)
        if kwargs:
            all_data = self._isbndb_api_client.request_data(**kwargs)
        elif is_isbn_code(
                keyword):  # Check first is a ISBN code to make a fast request
            all_data = self._isbndb_api_client.request_data(book=keyword)
        else:  # else search around all the collections
            all_data = self._isbndb_api_client.request_data(
                all_collections=keyword, query=True)
        return all_data
    def _remote_request_data(self, keyword):
        """ Get all the data from the requested keyword
            You can make a keyword like this:
                author: Richard Rowland
                subject: mechanism
            A keyword without ':' key means that you want to use "all the collections"
            URL to search any book
        """

        def _calculate_kwargs(keyword):
            """ Check if the keyword is like:
                book: Harry Potter && query: True && index: author_name
            """
            kwargs = {}
            queries = keyword.split('&&')
            for query in queries:
                fields = query.split(':')
                # If keyword is like, "subject: maths", etc.
                if len(fields) == 2:
                    _collection = fields[0].lower().strip()
                    _keyword = fields[1].strip()
                    if _collection in COLLECTIONS or _collection in QUERIES:
                        kwargs[_collection] = _keyword
                    else:
                        raise TaricGeneralException("This collection or query does not exist %s" %
                                                    _collection)
            _q = kwargs.get('query')
            if _q:
                if _q == 'True' or _q == 'true':
                    kwargs['query'] = True
                else:
                    kwargs['query'] = False
            return kwargs

        kwargs = _calculate_kwargs(keyword)
        if kwargs:
                all_data = self._isbndb_api_client.request_data(**kwargs)
        elif is_isbn_code(keyword):  # Check first is a ISBN code to make a fast request
            all_data = self._isbndb_api_client.request_data(book=keyword)
        else:  # else search around all the collections
            all_data = self._isbndb_api_client.request_data(all_collections=keyword, query=True)
        return all_data