Skip to content

Commit

Permalink
Created script to download images
Browse files Browse the repository at this point in the history
  • Loading branch information
NandaScott committed Nov 13, 2020
1 parent 75516be commit 2c09d66
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/download_images_by_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import scrython
import requests
import time

IMAGE_PATH = './' # You can replace this with whatever path

def get_set_code():
all_sets = scrython.sets.Sets()
for i, set_object in enumerate(all_sets.data()):
print(i, all_sets.data(i, "name"))

choice = int(input("Select your set by number: "))

code = all_sets.data(choice, "code")

return code

def save_image(path, url, name):
response = requests.get(url)

with open('{}{}.png'.format(path, name), 'wb') as f:
f.write(response.content)

def get_all_pages(set_code):
page_count = 1
all_data = []
while True:
time.sleep(0.5)
page = scrython.cards.Search(q='e:{}'.format(set_code), page=page_count)
all_data = all_data + page.data()
page_count += 1
if not page.has_more():
break

return all_data

def get_all_cards(card_array):
card_list = []
for card in card_array:
time.sleep(0.5)
id_ = card['id']
card = scrython.cards.Id(id=id_)
card_list.append(card)

return card_list

code = get_set_code()
card_list = get_all_pages(code)
card_list_objects = get_all_cards(card_list)

for card in card_list_objects:
time.sleep(0.1)
save_image(IMAGE_PATH, card.image_uris(0, 'normal'), card.name())

2 comments on commit 2c09d66

@Pho3nixprim3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, This looks amazing.
Can you help me understand some parts of your code, I wish to make a script to download the images from scryfall from a decklist. Eks commanderdeck1.text (format 1 sol ring)
I see that your script is doing something very similar. Can u help me with this ?

@NandaScott
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the time to go through and explain everything in this script. You can try running the code and stepping through it with print statements.

Please sign in to comment.