2018-10-26 01:21:02 +00:00
|
|
|
import sys
|
|
|
|
sys.path.append('..')
|
|
|
|
from scrython.foundation import FoundationObject
|
2018-02-17 00:27:25 +00:00
|
|
|
|
2018-10-26 01:21:02 +00:00
|
|
|
class Sets(FoundationObject):
|
2018-02-22 00:00:01 +00:00
|
|
|
"""
|
|
|
|
/sets
|
|
|
|
|
2018-10-26 01:35:36 +00:00
|
|
|
Args:
|
|
|
|
code (string): The 3 letter code of the set
|
|
|
|
format (string, optional):
|
|
|
|
Returns data in the specified method. Defaults to JSON.
|
|
|
|
pretty (string, optional):
|
|
|
|
Returns a prettier version of the json object. Note that this may break functionality with Scrython.
|
2018-02-22 00:00:01 +00:00
|
|
|
|
|
|
|
Example usage:
|
|
|
|
>>> set = scrython.sets.Sets()
|
2018-10-26 01:35:36 +00:00
|
|
|
>>> set.data(3, 'name')
|
2018-02-22 00:00:01 +00:00
|
|
|
"""
|
2018-02-17 00:31:08 +00:00
|
|
|
def __init__(self):
|
2018-02-17 00:27:25 +00:00
|
|
|
self._url = 'sets?'
|
|
|
|
super(Sets, self).__init__(self._url)
|
|
|
|
|
|
|
|
def object(self):
|
2018-10-26 01:35:36 +00:00
|
|
|
"""Returns the type of object it is
|
|
|
|
(card, error, etc)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
string
|
|
|
|
"""
|
2018-04-19 00:55:11 +00:00
|
|
|
super(Sets, self)._checkForKey('object')
|
2018-02-17 00:27:25 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['object']
|
|
|
|
|
|
|
|
def has_more(self):
|
2018-10-26 01:35:36 +00:00
|
|
|
"""True if there are more pages available
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
boolean
|
|
|
|
"""
|
2018-04-19 00:55:11 +00:00
|
|
|
super(Sets, self)._checkForKey('has_more')
|
2018-02-17 00:27:25 +00:00
|
|
|
|
|
|
|
return self.scryfallJson['has_more']
|
|
|
|
|
2018-10-26 01:35:36 +00:00
|
|
|
def data(self, index=None, key=None):
|
|
|
|
"""The data returned from the query
|
|
|
|
|
|
|
|
Acceptable keys:
|
|
|
|
object (string): The set object.
|
|
|
|
code (string): The three letter set code of the set.
|
|
|
|
mtgo_code (string): The mtgo equivalent of `code()`.
|
|
|
|
name (string): The full name of the set.
|
|
|
|
set_type (string): The type of the set (expansion, commander, etc)
|
|
|
|
released_at (string): The date the set was launched.
|
|
|
|
block_code (string): The the letter code for the block the set was in.
|
|
|
|
block (string): The full name of the block a set was in.
|
|
|
|
parent_set_code (string): The set code for the parent set.
|
|
|
|
card_count (integer): The number of cards in the set.
|
|
|
|
digital (boolean): True if this set is only featured on MTGO.
|
|
|
|
foil_only (boolean): True if this set only has foils.
|
|
|
|
icon_svg_uri (string): A URI to the SVG of the set symbol.
|
|
|
|
search_uri (string): The scryfall API url for the search.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index (integer, optional): Defaults to None. Access a specific index.
|
|
|
|
key (string, optional): Defaults to None. Returns the value of the given key. Requires the `index` argument.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List: The full list of data.
|
|
|
|
Dictionary: If given an index
|
|
|
|
String: If given an index and key.
|
|
|
|
"""
|
2018-04-19 00:55:11 +00:00
|
|
|
super(Sets, self)._checkForKey('data')
|
2018-02-17 00:27:25 +00:00
|
|
|
|
2018-10-26 01:35:36 +00:00
|
|
|
if index is not None:
|
|
|
|
if key is not None:
|
|
|
|
super(Sets, self)._checkForTupleKey('data', index, key)
|
|
|
|
return self.scryfallJson['data'][index][key]
|
|
|
|
|
|
|
|
return self.scryfallJson['data'][index]
|
|
|
|
|
2018-02-17 00:27:25 +00:00
|
|
|
return self.scryfallJson['data']
|
|
|
|
|
|
|
|
def data_length(self):
|
2018-10-26 01:35:36 +00:00
|
|
|
"""The length of the data returned
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
integer
|
|
|
|
"""
|
2018-04-19 00:55:11 +00:00
|
|
|
super(Sets, self)._checkForKey('data')
|
2018-02-17 00:27:25 +00:00
|
|
|
|
2018-10-26 01:35:36 +00:00
|
|
|
return len(self.scryfallJson['data'])
|