Example #1
0
 def search(self, name=None, author=None, category=None, offset=0, limit=None):
     qs = {
         "search": name,
         "author": author,
         "category": category,
         "offset": offset,
         "limit": (deck_list_max if limit is None else limit),
     }
     req = requests.get(self.deck_list_url, params=qs)
     if req.status_code == requests.codes.ok:
         return SearchReturn.from_json(req.json())
     elif req.status_code == requests.codes.not_found:
         err = "Search query returned not found"
         raise SearchNotFoundError(err) from req.raise_for_status()
     else:
         err = "Error searching decks"
         raise SearchRetrievalError(err) from req.raise_for_status()
Example #2
0
 def search(self,
            name=None,
            author=None,
            category=None,
            offset=0,
            limit=None):
     qs = {
         "search": name,
         "author": author,
         "category": category,
         "offset": offset,
         "limit": (deck_list_max if limit is None else limit)
     }
     req = requests.get(self.deck_list_url, params=qs)
     if req.status_code == requests.codes.ok:
         return SearchReturn.from_json(req.json())
     elif req.status_code == requests.codes.not_found:
         err = "Search query returned not found"
         raise SearchNotFoundError(err) from req.raise_for_status()
     else:
         err = "Error searching decks"
         raise SearchRetrievalError(err) from req.raise_for_status()
Example #3
0
        return Deck(deckinfo, cards[0], cards[1])

    @asyncio.coroutine
    def search(self, name=None, author=None, category=None, offset=0,
               limit=None):
        qs = {
            "search": name,
            "author": author,
            "category": category,
            "offset": offset,
            "limit": (deck_list_max if limit is None else limit)
        }
        req = yield from aiohtp.request("get", self.deck_list_url, params=qs)
        if req.status == 200:
            json = yield from req.json()
            return SearchReturn.from_json(json)
        elif req.status == 404:
            err = "Search query returned not found"
            raise SearchNotFoundError(err)
        else:
            err = "Error searching decks (code {})".format(req.status)
            raise SearchRetrievalError(err)

    def search_iter(self, name=None, author=None, category=None, offset=0,
                    limit=None):
        s = asyncio.run_until_complete(self.search(name, author, category,
                                                   offset, limit))

        while s.count > 0:
            yield s