2018-10-24 01:39:07 +00:00
|
|
|
import sys
|
|
|
|
sys.path.append('..')
|
|
|
|
from scrython.foundation import FoundationObject
|
2018-02-13 21:35:01 +00:00
|
|
|
import urllib.parse
|
2018-01-10 21:55:11 +00:00
|
|
|
|
2018-10-24 01:39:07 +00:00
|
|
|
class Autocomplete(FoundationObject):
|
2018-10-22 14:19:38 +00:00
|
|
|
"""
|
|
|
|
cards/autocomplete
|
|
|
|
Get a list of potential autocompletion phrases.
|
2018-02-21 19:42:58 +00:00
|
|
|
|
2018-10-23 21:59:03 +00:00
|
|
|
Args:
|
|
|
|
q (string):
|
|
|
|
The query of the autocompletion.
|
|
|
|
format (string, optional):
|
|
|
|
Defaults to 'json'.
|
|
|
|
Returns data in the specified method.
|
|
|
|
face (string, optional):
|
|
|
|
Defaults to empty string.
|
|
|
|
If you're using the `image` format,
|
|
|
|
this will specify if you want the front or back face.
|
|
|
|
version (string, optional):
|
|
|
|
Defaults to empty string.
|
|
|
|
If you're using the `image` format, this will specify
|
|
|
|
if you want the small, normal, large, etc version of the image.
|
|
|
|
pretty (string, optional):
|
|
|
|
Defaults to empty string.
|
|
|
|
Returns a prettier version of the json object.
|
|
|
|
Note that this may break functionality with Scrython.
|
2018-02-21 19:42:58 +00:00
|
|
|
|
2018-10-24 00:54:28 +00:00
|
|
|
Raises:
|
|
|
|
Exception: If the 'q' parameter is not provided.
|
|
|
|
Exception: If the object returned is an error.
|
|
|
|
|
2018-10-22 14:19:38 +00:00
|
|
|
Example usage:
|
|
|
|
>>> auto = scrython.cards.Autocomplete(q="Thal")
|
|
|
|
>>> auto.total_items()
|
|
|
|
"""
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
if kwargs.get('q') is None:
|
2018-10-24 00:54:28 +00:00
|
|
|
raise Exception('No query provided to search by')
|
2018-02-13 21:51:03 +00:00
|
|
|
|
2018-10-23 21:59:03 +00:00
|
|
|
self.dict = { 'q': kwargs.get('q') }
|
2018-01-10 21:55:11 +00:00
|
|
|
|
2018-10-22 14:19:38 +00:00
|
|
|
self.args = urllib.parse.urlencode(self.dict)
|
|
|
|
self.url = 'cards/autocomplete?' + self.args
|
|
|
|
super(Autocomplete, self).__init__(self.url)
|
2018-01-10 21:55:11 +00:00
|
|
|
|
2018-10-22 14:19:38 +00:00
|
|
|
def object(self):
|
2018-10-23 21:59:03 +00:00
|
|
|
"""Returns the type of object it is.
|
|
|
|
(card, error, etc)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
string: The type of object
|
|
|
|
"""
|
2018-10-22 14:19:38 +00:00
|
|
|
super(Autocomplete, self)._checkForKey('object')
|
2018-01-30 15:30:14 +00:00
|
|
|
|
2018-10-22 14:19:38 +00:00
|
|
|
return self.scryfallJson['object']
|
2018-01-10 21:55:11 +00:00
|
|
|
|
2018-10-23 16:17:01 +00:00
|
|
|
def total_values(self):
|
2018-10-23 21:59:03 +00:00
|
|
|
"""How many items are returned in `data`
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
int: The number of items in the `data` key
|
|
|
|
"""
|
2018-10-23 16:17:01 +00:00
|
|
|
super(Autocomplete, self)._checkForKey('total_values')
|
2018-01-30 15:30:14 +00:00
|
|
|
|
2018-10-23 16:17:01 +00:00
|
|
|
return self.scryfallJson['total_values']
|
2018-01-10 21:55:11 +00:00
|
|
|
|
2018-10-22 14:19:38 +00:00
|
|
|
def data(self):
|
2018-10-23 21:59:03 +00:00
|
|
|
"""The list of potential autocompletes
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
list: A list of possible corrections
|
|
|
|
"""
|
2018-10-22 14:19:38 +00:00
|
|
|
super(Autocomplete, self)._checkForKey('data')
|
2018-01-30 15:30:14 +00:00
|
|
|
|
2018-10-23 21:59:03 +00:00
|
|
|
return self.scryfallJson['data']
|