Merge pull request #54 from iggy12345/patch-1

Update cards_object.py
This commit is contained in:
Nanda Scott 2021-02-07 10:32:18 -05:00 committed by GitHub
commit 2936e6820d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 143 additions and 2 deletions

31
.github/workflows/python-publish.yml vendored Normal file
View File

@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*

View File

@ -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())

View File

@ -0,0 +1,56 @@
import scrython
import time
import json
import os.path
import re
# This file will parse a scryfall exported deck list and create a list of tokens
# needed for that deck. To run this, make sure that your deck file is in the same folder
# as this. You can then copy/paste the output file back into Scryfall to list all the
# tokens.
def get_cards():
with open('scryfall-deck.txt', 'r') as f:
cards_from_file = f.read().splitlines()
list_of_cards = []
for name in cards_from_file:
true_name = re.findall(r'[^\d\s//].*', name)
if true_name == ['Commander'] or len(true_name) == 0:
continue
else:
true_name = true_name[0]
list_of_cards.append(true_name)
data = { 'data': [] }
for i, card in enumerate(list_of_cards, start=1):
print('Fetching card: {} | {} of {}'.format(card, i, len(list_of_cards)))
card = scrython.cards.Named(fuzzy=card)
data['data'].append(card.scryfallJson)
time.sleep(0.5)
with open('scryfall_data.json', 'w+') as f:
f.write(json.dumps(data, sort_keys=True, indent=4))
def create_list():
with open('scryfall_data.json', 'r') as f:
data = json.load(f)
# Parses through each card in the full json we collected from get_cards
# If the card has the all_parts key, check if it's a token.
# If it is, fetch that token and record it's name and set code
with open('tokens_needed.txt', 'w') as f:
for card in data['data']:
if 'all_parts' in card:
for part in card['all_parts']:
if part['component'] == 'token':
token = scrython.cards.Id(id=part['id'])
time.sleep(0.1)
f.write('{} | {}\n'.format(token.name(), token.set_code()))
if not os.path.isfile('./scryfall_data.json'):
get_cards()
create_list()

View File

@ -175,7 +175,8 @@ class CardsObject(FoundationObject):
'emblem': lambda num: self.scryfallJson['image_uris'], 'emblem': lambda num: self.scryfallJson['image_uris'],
'augment': lambda num: self.scryfallJson['image_uris'], 'augment': lambda num: self.scryfallJson['image_uris'],
'host': lambda num: self.scryfallJson['image_uris'], 'host': lambda num: self.scryfallJson['image_uris'],
'adventure': lambda num: self.scryfallJson['image_uris'] 'adventure': lambda num: self.scryfallJson['image_uris'],
'modal_dfc': lambda num: self.scryfallJson['card_faces'][num]['image_uris']
} }
image_types = { image_types = {