/
spoiler_season.py
76 lines (58 loc) · 2.2 KB
/
spoiler_season.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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'], card['card_faces'][0]['rarity']))
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)