Exemple #1
0
def db(request):
    if request.param == 'url':
        return CardDb.from_url()
    elif request.param == 'file':
        return CardDb.from_file(download_set_file(ALL_SETS_URL,
                                                  'AllSets.json'))
    elif request.param == 'file-x':
        return CardDb.from_file(
            download_set_file(ALL_SETS_X_URL, 'AllSets-x.json'))
Exemple #2
0
def db(request):
    if request.param == 'url':
        return CardDb.from_url()
    elif request.param == 'file':
        return CardDb.from_file(
            download_set_file(ALL_SETS_URL, 'AllSets.json')
        )
    elif request.param == 'file-x':
        return CardDb.from_file(
            download_set_file(ALL_SETS_X_URL, 'AllSets-x.json')
        )
#!/usr/bin/python
# converts a tappedout .txt file to a folder with card images
# to be used with the tabletop simulator deck creator
# requires mtgjson, beautifulsoup4, requests

from mtgjson import CardDb
from bs4 import BeautifulSoup
import Tkinter, tkFileDialog, tkMessageBox, os, urllib, urllib2, re

if not os.path.isdir('Decks'):
	os.mkdir('Decks')

if os.path.isfile('AllSets.json'):
	print "Using cached JSON file..."
	db = CardDb.from_file('AllSets.json')
else:
	print "Downloading JSON Card DB..."
	db = CardDb.from_url("http://mtgjson.com/json/AllSets.json")
root = Tkinter.Tk()
root.withdraw()
tkMessageBox.showinfo(title="HEY", message="Point me to your txt file for the deck you made on TappedOut.")
path_to_file = tkFileDialog.askopenfilename(filetypes=[("Text files","*.txt")])
deck_name = raw_input("Deck name: ")
isSideboard = False
if not os.path.isdir('Decks/'+deck_name):
	os.mkdir('Decks/'+deck_name)

def alternateGetImage(card):
	page = BeautifulSoup(urllib2.urlopen('http://magiccards.info/query?q=!'+card[1].replace(' ', '+')+'&v=card&s=cname').read())
	return page.find("img", src=re.compile(".info/scans/en"))["src"]
	
Exemple #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from pprint import pprint
import codecs
import sys
from get_ability import *
import re
from mtgjson import CardDb

#create db
db = CardDb.from_file(db_file='AllSets.json')

#read in our list of cards to check
with open('ORI.json', encoding="utf-8") as f:
    lines = f.read()
    print(type(lines))
    lines = json.loads(lines)
    #x = str(lines).encode("utf-8")
#print(x)
#print(str(lines['cards']).encode('utf-8'))
#getlist of cards
card_list = []

for key in lines['cards']:
    if "<class 'str'>" in key['name']:
        continue
    name = key['name'].encode('utf-8').decode('UTF-8')
    card = db.cards_by_name[name]

    if "Creature" == card.types[0]:
Exemple #5
0
    os.mkdir(cache_dir)
if not os.path.exists(output_dir + "/.json"):
    os.mkdir(output_dir + "/.json")
if not os.path.exists(output_dir + "/.infill"):
    os.mkdir(output_dir + "/.infill")

# attempt to init from file, if not able, do from url
MTG_JSON_URL = "https://mtgjson.com/json/AllSets.json.zip"
MTG_JSON_ZIP = json_dir + "/AllSets.json.zip"
MTG_JSON_FILE = json_dir + "/AllSets.json"
if not os.path.isfile(MTG_JSON_ZIP):
    urllib.urlretrieve(MTG_JSON_URL, MTG_JSON_ZIP)
zip_ref = zipfile.ZipFile(MTG_JSON_ZIP, "r")
zip_ref.extractall(output_dir + "/.json")
zip_ref.close()
db = CardDb.from_file(MTG_JSON_FILE)

# get release dates for card frame magic
BFZ_RELEASE = db.sets.get("BFZ").releaseDate
M_15_RELEASE = db.sets.get("M15").releaseDate
M_08_RELEASE = db.sets.get("8ED").releaseDate
M_06_RELEASE = db.sets.get("6ED").releaseDate
M_04_RELEASE = db.sets.get("4ED").releaseDate

# string patterns for save location
SAVE_MODIFIED_PATTERN = "{:s}/{:s}"
SAVE_CACHE_PATTERN = "{:s}/.cache/{:s}"

# compile regular expression to remove leading numbers
LINE_PATTERN_REGEX = re.compile(r"^[0-9]+?[ ]+?(.+)$")