-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75516be
commit 2c09d66
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
2c09d66
There was a problem hiding this comment.
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 ?
2c09d66
There was a problem hiding this comment.
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.