Skip to content

Instantly share code, notes, and snippets.

@spiiin
Created January 14, 2019 04:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiiin/d6b1ec3dca17fbbedf6c03856cb48634 to your computer and use it in GitHub Desktop.
Save spiiin/d6b1ec3dca17fbbedf6c03856cb48634 to your computer and use it in GitHub Desktop.
Using steemmonsters python library for winning Gold Card in contest
import steemmonsters.api
from itertools import permutations
import hashlib
api = steemmonsters.api.Api()
#get info about cards
cards_details = api.get_card_details()
#debug print of card info
for cd in cards_details:
print(cd)
#filter for common and rare cards
common = [(c.get("name")) for c in cards_details if c.get("rarity")==1]
rare = [(c.get("name")) for c in cards_details if c.get("rarity")==2]
print("Card names recieved. Total: %d common cards and %d rare cards)"%(len(common), len(rare)))
#fill list of card names
cards_names = common + rare
#convert string to sha245 and check if hash is equal to answer
def checkHash(myStr):
m = hashlib.sha256()
m.update(myStr.encode('utf-8'))
return m.hexdigest() == "8iu7O23u9SRnkdjckjh29cZ3E9pOpCXJhwfdQjCM3bohrSfbo9541122GnXI9w8J"
#generate all permutations for card_names
all_permuations = permutations(cards_names, 3)
for i, p in enumerate(all_permuations):
#join list elements to string with ", " as separator
s = ", ".join([pp.upper() for pp in p])
#print debug results for every 1000th value to view progress
if i % 1000 == 0:
print(i)
print(s)
#if we found answer, print it and break search
if (checkHash(s)):
print(s)
break
#print card name and it's rarity
def getCardInfo(p):
#search, if card_detail_id for our card is found is cards_details dictionary
for cd in cards_details:
if cd.get("id") == p.get("card_detail_id"):
#if card_detail_id matches, return card name and rarity
return (cd.get("name"), cd.get("rarity"))
#read full card collection for user
pd = api.get_collection("nomadic-maverick")
for p in pd.get("cards"):
#if we found gold card, print it's name and rarity
if p.get("gold") == True:
print(getCardInfo(p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment