Changed a whole bunch of stuff.
This commit is contained in:
parent
d92aad46b6
commit
958c332e65
|
@ -2,3 +2,4 @@ __pycache__
|
||||||
.ropeproject
|
.ropeproject
|
||||||
scrython.egg-info
|
scrython.egg-info
|
||||||
dist
|
dist
|
||||||
|
tests
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import scrython
|
import scrython
|
||||||
|
|
||||||
getCard = input("What card would you like me to search? ")
|
getCard = str(input("What card would you like me to search? "))
|
||||||
|
|
||||||
card = scrython.cards.Named(fuzzy=getCard)
|
card = scrython.cards.Named(fuzzy=getCard)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
import scrython, time
|
||||||
|
|
||||||
|
def keyCheck(key, _dict):
|
||||||
|
try:
|
||||||
|
_dict[key]
|
||||||
|
return True
|
||||||
|
except KeyError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def nameBar(name, manaCost):
|
||||||
|
return "{} {}".format(name, manaCost)
|
||||||
|
|
||||||
|
def typeBar(typeLine, rarity):
|
||||||
|
return "{} | {}".format(typeLine, rarity[:1].upper())
|
||||||
|
|
||||||
|
def powerAndToughness(power, toughness):
|
||||||
|
return "{}/{}".format(power, toughness)
|
||||||
|
|
||||||
|
query = input("Enter a set: ")
|
||||||
|
|
||||||
|
currentSetSize = 0
|
||||||
|
lastList = []
|
||||||
|
currentList = []
|
||||||
|
|
||||||
|
while query is not None:
|
||||||
|
|
||||||
|
#Grab the data
|
||||||
|
spoilers = scrython.cards.Search(q="++e:{}".format(query), order='spoiled')
|
||||||
|
|
||||||
|
#If the total cards has increased
|
||||||
|
if spoilers.total_cards() > currentSetSize:
|
||||||
|
|
||||||
|
#Dump if currentList already exists
|
||||||
|
if currentList:
|
||||||
|
del currentList[:]
|
||||||
|
|
||||||
|
#If there aren't enough spoilers we iterate through the whole list.
|
||||||
|
#Otherwise we only want the first 15
|
||||||
|
if spoilers.total_cards() > 15:
|
||||||
|
maxIteration = 15
|
||||||
|
else:
|
||||||
|
maxIteration = spoilers.total_cards()
|
||||||
|
|
||||||
|
for i in range(maxIteration):
|
||||||
|
currentList.append(spoilers.data()[i]['id'])
|
||||||
|
|
||||||
|
#Iterate through data
|
||||||
|
for card in reversed(spoilers.data()):
|
||||||
|
if card['id'] in lastList:
|
||||||
|
continue
|
||||||
|
print("~~~~~~~~~~\nNew card:")
|
||||||
|
|
||||||
|
#Grab the relevant keys
|
||||||
|
if keyCheck('card_faces', card):
|
||||||
|
print(nameBar(card['name'], card['card_faces'][0]['mana_cost']))
|
||||||
|
print(typeBar(card['card_faces'][0]['mana_cost']))
|
||||||
|
else:
|
||||||
|
print(nameBar(card['name'], card['mana_cost']))
|
||||||
|
print(typeBar(card['type_line'], card['rarity']))
|
||||||
|
|
||||||
|
if keyCheck('oracle_text', card):
|
||||||
|
print(card['oracle_text'])
|
||||||
|
|
||||||
|
if keyCheck('power', card) and keyCheck('toughness', card):
|
||||||
|
print(powerAndToughness(card['power'], card['toughness']))
|
||||||
|
|
||||||
|
#Update card count
|
||||||
|
currentSetSize = spoilers.total_cards()
|
||||||
|
#Dump all in last list
|
||||||
|
if lastList:
|
||||||
|
del lastList[:]
|
||||||
|
#Add the first 15 ids in current list to last list
|
||||||
|
for i in range(maxIteration):
|
||||||
|
lastList.append(currentList[i])
|
||||||
|
|
||||||
|
time.sleep(300)
|
|
@ -5,5 +5,5 @@ class Id(CardsObject):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
|
|
||||||
self.url = 'cards/' + str(kwargs.get('id'))
|
self.url = 'cards/{}?'.format(str(kwargs.get('id')))
|
||||||
super(Id, self).__init__(self.url)
|
super(Id, self).__init__(self.url)
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
class CardsObject(object):
|
class CardsObject(object):
|
||||||
def __init__(self, _url, **kwargs):
|
def __init__(self, _url, **kwargs):
|
||||||
self._url = 'https://api.scryfall.com/' + _url
|
|
||||||
|
self.params = {
|
||||||
|
'format': kwargs.get('format', 'json'), 'face': kwargs.get('face', ''),
|
||||||
|
'version': kwargs.get('version', ''), 'pretty': kwargs.get('pretty', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
self.encodedParams = urllib.parse.urlencode(self.params)
|
||||||
|
self._url = 'https://api.scryfall.com/' + _url + "&" + self.encodedParams #Find a fix for this later
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
self.session = aiohttp.ClientSession(loop=loop)
|
self.session = aiohttp.ClientSession(loop=loop)
|
||||||
|
|
||||||
|
@ -11,14 +19,7 @@ class CardsObject(object):
|
||||||
async with self.session.get(url, **kwargs) as response:
|
async with self.session.get(url, **kwargs) as response:
|
||||||
return await response.json()
|
return await response.json()
|
||||||
|
|
||||||
self.scryfallJson = loop.run_until_complete(getRequest(
|
self.scryfallJson = loop.run_until_complete(getRequest(url = self._url))
|
||||||
url = self._url,
|
|
||||||
params={
|
|
||||||
'format': kwargs.get('format', 'None'),
|
|
||||||
'face': kwargs.get('face', 'None'),
|
|
||||||
'version': kwargs.get('version', 'None'),
|
|
||||||
'pretty': kwargs.get('pretty', 'None')
|
|
||||||
}))
|
|
||||||
|
|
||||||
if self.scryfallJson['object'] == 'error':
|
if self.scryfallJson['object'] == 'error':
|
||||||
self.session.close()
|
self.session.close()
|
||||||
|
@ -154,7 +155,7 @@ class CardsObject(object):
|
||||||
|
|
||||||
def set_code(self):
|
def set_code(self):
|
||||||
if self.__checkForKey('set') is None:
|
if self.__checkForKey('set') is None:
|
||||||
raise KeyError("This card has no key \'set_code\'")
|
raise KeyError("This card has no key \'set\'")
|
||||||
|
|
||||||
return self.scryfallJson['set']
|
return self.scryfallJson['set']
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ class Collector(CardsObject):
|
||||||
if kwargs.get('code') is None:
|
if kwargs.get('code') is None:
|
||||||
raise TypeError('No code provided to search by')
|
raise TypeError('No code provided to search by')
|
||||||
|
|
||||||
self.url = 'cards/{}/{}'.format(kwargs.get('code'), str(kwargs.get('collector_number')))
|
self.url = 'cards/{}/{}?'.format(kwargs.get('code'), str(kwargs.get('collector_number')))
|
||||||
super(Collector, self).__init__(self.url)
|
super(Collector, self).__init__(self.url)
|
||||||
|
|
|
@ -5,5 +5,6 @@ class Mtgo(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
self.url = 'cards/mtgo/' + str(kwargs.get('id'))
|
|
||||||
|
self.url = 'cards/mtgo/{}?'.format(str(kwargs.get('id')))
|
||||||
super(Mtgo, self).__init__(self.url)
|
super(Mtgo, self).__init__(self.url)
|
||||||
|
|
|
@ -4,5 +4,6 @@ class Multiverse(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
self.url = 'cards/multiverse/' + kwargs.get('id')
|
|
||||||
|
self.url = 'cards/multiverse/{}?'.format(str(kwargs.get('id')))
|
||||||
super(Multiverse, self).__init__(self.url)
|
super(Multiverse, self).__init__(self.url)
|
||||||
|
|
|
@ -4,11 +4,15 @@ import urllib.parse
|
||||||
class Named(CardsObject):
|
class Named(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.dict = {
|
self.dict = {
|
||||||
'exact':kwargs.get('exact', ''),
|
'set':kwargs.get('set', '')
|
||||||
'fuzzy':kwargs.get('fuzzy', ''),
|
|
||||||
'set':kwargs.get('set', 'none')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kwargs.get('exact') is not None:
|
||||||
|
self.dict['exact'] = kwargs.get('exact')
|
||||||
|
|
||||||
|
if kwargs.get('fuzzy') is not None:
|
||||||
|
self.dict['fuzzy'] = kwargs.get('fuzzy')
|
||||||
|
|
||||||
self.args = urllib.parse.urlencode(self.dict)
|
self.args = urllib.parse.urlencode(self.dict)
|
||||||
self.url = 'cards/named?' + self.args
|
self.url = 'cards/named?' + self.args
|
||||||
super(Named, self).__init__(self.url)
|
super(Named, self).__init__(self.url)
|
||||||
|
|
|
@ -3,5 +3,5 @@ from .cards_object import CardsObject
|
||||||
|
|
||||||
class Random(CardsObject):
|
class Random(CardsObject):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.url = 'cards/random'
|
self.url = 'cards/random?'
|
||||||
super(Random, self).__init__(self.url)
|
super(Random, self).__init__(self.url)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from .rulings_object import RulingsObject
|
||||||
class Mtgo(RulingsObject):
|
class Mtgo(RulingsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
|
|
||||||
self.url = 'cards/mtgo/{}/rulings'.format(str(kwargs.get('id')))
|
self.url = 'cards/mtgo/{}/rulings'.format(str(kwargs.get('id')))
|
||||||
super(Mtgo, self).__init__(self.url)
|
super(Mtgo, self).__init__(self.url)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from .rulings_object import RulingsObject
|
||||||
class Multiverse(RulingsObject):
|
class Multiverse(RulingsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
|
|
||||||
self.url = 'cards/multiverse/{}/rulings'.format(str(kwargs.get('id')))
|
self.url = 'cards/multiverse/{}/rulings'.format(str(kwargs.get('id')))
|
||||||
super(Multiverse, self).__init__(self.url)
|
super(Multiverse, self).__init__(self.url)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from .rulings_object import RulingsObject
|
||||||
class Id(RulingsObject):
|
class Id(RulingsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs.get('id') is None:
|
if kwargs.get('id') is None:
|
||||||
raise TypeError('No id provided to search by')
|
raise TypeError('No id provided to search by')
|
||||||
|
|
||||||
self.url = 'cards/{}/rulings'.format(str(kwargs.get('id')))
|
self.url = 'cards/{}/rulings'.format(str(kwargs.get('id')))
|
||||||
super(Id, self).__init__(self.url)
|
super(Id, self).__init__(self.url)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open('README.md') as f:
|
||||||
setup(
|
setup(
|
||||||
name='scrython',
|
name='scrython',
|
||||||
packages=['scrython', 'scrython.cards', 'scrython.rulings'],
|
packages=['scrython', 'scrython.cards', 'scrython.rulings'],
|
||||||
version='0.2.0',
|
version='0.4.0',
|
||||||
description='A wrapper for using the Scryfall API.',
|
description='A wrapper for using the Scryfall API.',
|
||||||
long_description=readme,
|
long_description=readme,
|
||||||
url='https://github.com/NandaScott/Scrython',
|
url='https://github.com/NandaScott/Scrython',
|
||||||
|
|
Loading…
Reference in New Issue