def get_edition_list(self): """ Loads all editions from the API. For a SET, mtg api has the following properties: # code # name # gatherer_code old_code # magic_cards_info_code # release_date # border # type # block online_only booster mkm_id mkm_name We are using the commented ones, but more could be fetched from the API. """ editions = [] all_sets = Set.all() for s in all_sets: editions.append([s.code, s.name, s.gatherer_code, s.magic_cards_info_code, s.release_date, s.border, s.type, s.block]) return editions
def _get_all_sets(self): """ Iterate through MTGSDK and extend all Set objects to self.sets. """ self.sets.extend(Set.all()) self.stdout.write(f'Grabbed {len(self.sets)} sets.')
def downloadSets(self): #Downloading all sets name in one file sets = Set.all() with open('dataSet/allSets.csv', 'w', encoding='utf-8') as csvfile: writer = csv.writer(csvfile, delimiter=',',quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow(['name', 'code', 'mkm_id', 'mkm_name', 'release_date']) for set in sets: writer.writerow([set.name, set.code, set.mkm_id, set.mkm_name, set.release_date])
def GetAllSets(): mtgsets = MTGSet.all() sets = [] for mtgset in mtgsets: sett = Objects.Set(mtgset.code, mtgset.name) sets.append(sett) return sets
def sync_sets(self): sets = list(api_set.all()) for set in sets: body = { 'full_name': set.name, 'abbreviation': set.code, 'release_date': set.release_date, 'type': set.type } Set.objects.update_or_create(defaults=body, abbreviation=set.code)
def season(): page = "" sets = Set.all() sets = [s for s in sets if s.type == 'core' or s.type == 'expansion'] list.sort(sets, key=lambda s: s.release_date, reverse=True) page += "<script src='static/mtgleague.js?test=%s'></script>\n" % uuid.uuid4( ) page += "<h1>MTG League Season</h1>\n" page += '<select id="setname" onchange="newSeason.updateStatus()">\n' for set in sets: setId = set.code setInfo = "%s [%s - %s]" % (set.name, set.type, set.release_date) page += " <option value='%s'>%s</option>\n" % (setId, setInfo) page += '</select>\n' page += ''' <button onclick="newSeason.create()" id="createButton">create</button> <button onclick="newSeason.reset()" id="resetButton">reset</button> <br/> <div>status: <span id="status"></div> <div id="season-state-div">state: <span id="season-state"></span> <button onclick="newSeason.advance()" id="advanceButton">advance</button> </div> <div id="SeasonContent"> <div id="Players"><h2>Players</h2> <div id="player-registration"> <input type="text" id="newPlayerName" placeholder="Please use your office login"/><button onclick="newSeason.registerPlayer()">register</button> </div> <table id="players-table"></table> </div> <div id="Matches"> <h2>Matches</h2> <select id="match-week" onchange="newSeason.updateMatches()"></select> <table id="match-table"></table> </div> <div id="rarepool"> <h2>Rare Pool</h2> <div>Redeem Rare: <select id="rare-sel-player"></select> <select id="rare-sel-card" onchange="newSeason.updateRareSelImg()"></select> <button onclick="newSeason.redeemRare()">redeem</button> <img id="rare-sel-img" src="" alt="no image"/> </div> <table id="rarepool-table"></table> </div> </div> <script type='text/javascript'> window.onload = newSeason.updateStatus() var playerNameInput = document.getElementById('newPlayerName') playerNameInput.addEventListener("keydown", function(evt) { if (evt.keyCode == 13) { newSeason.registerPlayer() ; playerNameInput.value="" }}) </script>''' return page
def query_and_write_sets(): setlist = [] print("query all sets") sets = Set.all() print("number of sets: " + str(len(sets))) for set in sets: dic = {'name': set.name, 'code': set.code} setlist.append(dic) write_json(setlist, "mtg_sets.json") print("all sets written to 'mtg_sets.json'") del setlist
def net_load_set_list() -> dict: """ Load the list of all MTG sets from the Gather""" try: start = time() sets = Set.all() stop = time() log("Fetched set list in {}s".format(round(stop - start, 3)), LogLevel.Info) except MtgException as err: log(str(err), LogLevel.Error) return {} return [set.__dict__ for set in sets]
def updateAll(self): psets = PersistentList() pcards = PCardList() for seti in mtgsdkSet.all(): pset = PSet(seti) setCards = [ PCard(card) for card in mtgsdkCard.where(set=seti.code).all() ] pset.extend(setCards) psets.append(pset) pcards.extend(setCards) print(pset, len(pcards), len(psets)) self.root.sets = psets self.root.cards = pcards transaction.commit() print(self.sets) print(self.cards)
def __init__(self, root): self.root = root root.title("MTG Set Checker") # Define screen size based on user's screen screen_width = int(root.winfo_screenwidth() / 2) screen_height = int(root.winfo_screenheight() / 2) self.width = screen_width self.height = screen_height window_geometry = str(self.width) + 'x' + str(self.height) self.root.geometry(window_geometry) # Retrieve from MTGSDK, sort by release date, and pass into ScrollCanvas self.sets = Set.all() self.sets.sort(key=lambda set: set.release_date, reverse=True) setNames = list(set.name for set in self.sets) # Create Scroll Canvas self.setCheck = ScrollCanvas(root, setNames) # Test button for Check Button variable self.ok = Button(root, text="OK", command=self.printVar) # Add Clear Button self.clear = Button(root, text="Uncheck", command=self.uncheck) # Create Entry for Search # Create StringVar and bind to callback function on change sv = StringVar() sv.trace("w", lambda name, index, mode, sv=sv: self.update(sv)) self.search = Entry(root, textvariable = sv) # Create ScrolledText for Cards cardsVar = StringVar() self.cards = ScrolledText(root) self.make_grid()
def test_all_returns_all_sets(self): with vcr.use_cassette('fixtures/all_sets.yaml'): sets = Set.all() self.assertGreater(len(sets), 190)
def fetch_a_card(self) -> MTGCard: card = secrets.choice(Card.where(set=secrets.choice(Set.all()).code).all()) return self._fetch_from_scryfall(card)
import json from mtgsdk import Card, Set, Subtype with open('logo.json') as surl: surldict = json.load(surl) sets = Set.all() print("{") print("\"allsets\": [") for iset in sets: cardSetList = Card.where(set=iset.code) \ .all() print("{") set_code = "none" if iset.code is not None: set_code = iset.code print("\"code\":" + "\"" + set_code + "\",") set_name = "none" if iset.name is not None: set_name = iset.name print("\"name\":" + "\"" + set_name + "\",") set_rDate = "none" if iset.release_date is not None: set_rDate = iset.release_date print("\"rDate\":" + "\"" + set_rDate + "\",")
html = ''' <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="//cdn.jsdelivr.net/npm/keyrune@latest/css/keyrune.css" rel="stylesheet" type="text/css" /> <link rel='stylesheet' href='style.css'> </head> <body> {} </body> </html> ''' sets = Set.all() sets.sort(key=lambda x: x.release_date, reverse=True) mtg_list = [] for set in sets: if set.online_only != 1: mtg_list.append({ 'code': set.code.lower(), 'name': set.name, 'month': calendar.month_name[strptime(set.release_date, '%Y-%m-%d').tm_mon], 'year': strptime(set.release_date, '%Y-%m-%d').tm_year }) items = []
def retrieve_sets(): return [i.__dict__ for i in Set.all()]
def net_load_sets(): try: sets = Set.all() except: return "" return sets
def magicSetsDataRequest(): sets = Set.all() addSetsToDatabase(sets)
def UpdateDB(): #This is the master update script #Will first refresh the SETS table and then check to see if any sets are not present on CARDS table #Will then attempt to grab all cards in all sets that are currently not present #WARNING: #Will take a long time on first load. #Reccommend using UpdateSet() if you only care about specific sets. from mtgsdk import Card from mtgsdk import Set import sqlite3 import base64 import urllib.request, io import contextlib conn = sqlite3.connect('mtgDB.db') c = conn.cursor() #Drop tables c.executescript(''' DROP TABLE IF EXISTS sets; DROP TABLE IF EXISTS mtgsets; ;''') print('Sets Table Dropped') c.execute('''CREATE TABLE if not exists sets ( id INTEGER UNIQUE PRIMARY KEY NOT NULL, code VARCHAR (255), name VARCHAR (255), gatherer_code VARCHAR (255), old_code VARCHAR (255), magic_cards_info_code VARCHAR (255), release_date VARCHAR (255), border VARCHAR (255), stype VARCHAR (255), block VARCHAR (255), online_only VARCHAR (255), booster VARCHAR (255), mkm_id VARCHAR (255), mkm_name VARCHAR (255) );''') print("Sets Table created") #insert values sets = Set.all() for x in range (0, len(sets)): code =str(sets[x].code) name =str(sets[x].name) gatherer_code =str(sets[x].gatherer_code) old_code =str(sets[x].old_code) magic_cards_info_code =str(sets[x].magic_cards_info_code) release_date =str(sets[x].release_date) border =str(sets[x].border) stype =str(sets[x].type) block =str(sets[x].block) online_only =str(sets[x].online_only) booster =str(sets[x].booster) mkm_id =str(sets[x].mkm_id) mkm_name =str(sets[x].mkm_name) #to prevent single quote insert errors name = name.replace("'", "''") c.execute("INSERT INTO sets VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(None,code,name,gatherer_code,old_code,magic_cards_info_code,release_date,border,stype,block,online_only,booster,mkm_id,mkm_name )) #print("Set #" + str(x) + " of " + str(len(sets))) print('Sets Table Populated') #Clear 'NONE' values from SETS c.execute('''UPDATE sets SET id = null where id='None' ''') c.execute('''UPDATE sets SET code = null where code='None' ''') c.execute('''UPDATE sets SET name = null where name='None' ''') c.execute('''UPDATE sets SET gatherer_code = null where gatherer_code='None' ''') c.execute('''UPDATE sets SET old_code = null where old_code='None' ''') c.execute('''UPDATE sets SET magic_cards_info_code = null where magic_cards_info_code='None' ''') c.execute('''UPDATE sets SET release_date = null where release_date='None' ''') c.execute('''UPDATE sets SET border = null where border='None' ''') c.execute('''UPDATE sets SET stype = null where stype='None' ''') c.execute('''UPDATE sets SET block = null where block='None' ''') c.execute('''UPDATE sets SET online_only = null where online_only='None' ''') c.execute('''UPDATE sets SET booster = null where booster='None' ''') c.execute('''UPDATE sets SET mkm_id = null where mkm_id='None' ''') c.execute('''UPDATE sets SET mkm_name = null where mkm_name='None' ''') print('Sets Table Cleaned') c.execute("SELECT DISTINCT code from sets where code not in (select distinct set_code from cards)") codes = c.fetchall() z = 0 print("Adding cards from the following Sets:") print(codes) for z in range(0, len(codes)-1): codes[z] = str(codes[z]).replace('(','') codes[z] = codes[z].replace(')','') codes[z] = codes[z].replace(',','') codes[z] = codes[z].replace('\'','') print("Now getting cards from: " + codes[z]) for y in range (1, 10000): cards = Card.where(set=codes[z]).where(page=y).where(pageSize=100).where(orderBy='set').all() #cards = Card.where(orderBy='name').all() for x in range (0, len(cards)): name =str(cards[x].name) multiverse_id =str(cards[x].multiverse_id) layout =str(cards[x].layout) names =str(cards[x].names) mana_cost =str(cards[x].mana_cost) cmc =str(cards[x].cmc) colors =str(cards[x].colors) color_identity =str(cards[x].color_identity) type_line =str(cards[x].type) types =str(cards[x].types) supertypes =str(cards[x].supertypes) subtypes =str(cards[x].subtypes) rarity =str(cards[x].rarity) text =str(cards[x].text) flavor =str(cards[x].flavor) artist =str(cards[x].artist) number =str(cards[x].number) power =str(cards[x].power) toughness =str(cards[x].toughness) loyalty =str(cards[x].loyalty) set_code =str(cards[x].set) set_name =str(cards[x].set_name) image_url =str(cards[x].image_url) border =str(cards[x].border) # and len(str(cards[x].names)) == 0 if cards[x].names is not None and len(cards[x].names) != 0: #print(cards[x].names) if cards[x].names.index(name) == 0: names = cards[x].names[1] else: names = cards[x].names[0] #Image BLOB data = None if cards[x].image_url is not None: #method to download card images from the with contextlib.closing(urllib.request.urlopen(image_url, data)) as fp: image = base64.b64encode(fp.read()) else: image = "No Image Available" #to prevent single quote import issues text = text.replace("'", "''") flavor = flavor.replace("'", "''") name = name.replace("'", "''") names = names.replace("'", "''") names = names.replace('[', '') names = names.replace(']', '') names = names.replace('"', '') set_name = set_name.replace("'", "''") artist = artist.replace("'", "''") mana_cost = mana_cost.replace('{', '') mana_cost = mana_cost.replace('}', '') color_identity = color_identity.replace('[', '') color_identity = color_identity.replace(']', '') color_identity = color_identity.replace(',', '') color_identity = color_identity.replace(' ', '') color_identity = color_identity.replace("'", '') types = types.replace('[', '') types = types.replace(']', '') types = types.replace(',', '') types = types.replace("'", '') supertypes = supertypes.replace('[', '') supertypes = supertypes.replace(']', '') supertypes = supertypes.replace(',', '') supertypes = supertypes.replace("'", '') subtypes = subtypes.replace('[', '') subtypes = subtypes.replace(']', '') subtypes = subtypes.replace(',', '') subtypes = subtypes.replace("'", '') colors = colors.replace('White', 'W') colors = colors.replace('Blue', 'U') colors = colors.replace('Black', 'B') colors = colors.replace('Red', 'R') colors = colors.replace('Green', 'G') colors = colors.replace(']', '') colors = colors.replace('[', '') colors = colors.replace(',', '') colors = colors.replace(' ', '') colors = colors.replace("'", "") c.execute("INSERT INTO cards VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(None,name,multiverse_id,layout,names,mana_cost,cmc,colors,color_identity,type_line,supertypes,types,subtypes,rarity,text,flavor,artist,number,power,toughness,loyalty,border,image_url,set_code,set_name, image)) print(name + ' ' + set_code) if(len(cards) == 0): conn.commit() break #cards c.execute('''UPDATE cards SET id = null where id='None' ''') c.execute('''UPDATE cards SET name = null where name='None' ''') c.execute('''UPDATE cards SET multiverse_id = null where multiverse_id='None' ''') c.execute('''UPDATE cards SET layout = null where layout='None' ''') c.execute('''UPDATE cards SET names = null where names='None' ''') c.execute('''UPDATE cards SET mana_cost = null where mana_cost='None' ''') c.execute('''UPDATE cards SET cmc = null where cmc='None' ''') c.execute('''UPDATE cards SET colors = null where colors='None' ''') c.execute('''UPDATE cards SET color_identity = null where color_identity='None' ''') c.execute('''UPDATE cards SET type_line = null where type_line='None' ''') c.execute('''UPDATE cards SET supertypes = null where supertypes='None' ''') c.execute('''UPDATE cards SET types = null where types='None' ''') c.execute('''UPDATE cards SET subtypes = null where subtypes='None' ''') c.execute('''UPDATE cards SET rarity = null where rarity='None' ''') c.execute('''UPDATE cards SET text = null where text='None' ''') c.execute('''UPDATE cards SET flavor = null where flavor='None' ''') c.execute('''UPDATE cards SET artist = null where artist='None' ''') c.execute('''UPDATE cards SET number = null where number='None' ''') c.execute('''UPDATE cards SET power = null where power='None' ''') c.execute('''UPDATE cards SET toughness = null where toughness='None' ''') c.execute('''UPDATE cards SET loyalty = null where loyalty='None' ''') c.execute('''UPDATE cards SET border = null where border='None' ''') c.execute('''UPDATE cards SET image_url = null where image_url='None' ''') c.execute('''UPDATE cards SET set_code = null where set_code='None' ''') c.execute('''UPDATE cards SET set_name = null where set_name='None' ''') # Save (commit) the changes conn.commit() # We can also close the connection if we are done with it. # Just be sure any changes have been committed or they will be lost. conn.close() print("done")
__author__ = "Duncan Seibert" from collections import defaultdict from mtgsdk import Set from APIutils import Block # creates a dict mapping block names to the sets that block contains _sets = [set_ for set_ in Set.all() if set_.block and set_.type == 'expansion'] block_names = set(set_.block for set_ in _sets) blocks: defaultdict[Block, list[Set]] = defaultdict(list) for set_ in _sets: blocks[set_.block].append(set_)
def fetch_a_card(self) -> Card: return random.choice( Card.where(set=random.choice(Set.all()).code).all())
def fetch_a_card(self) -> Card: return random.choice( Card.where(set=random.choice(Set.all()).code).where( rarity='Uncommon').all())
__author__ = "Duncan Seibert" from collections import Counter from typing import NewType import mtgsdk from mtgsdk import Set Set_code = NewType('Set_code', str) Set_name = NewType('Set_Name', str) Block = NewType('Block', str) Cardname = NewType('Cardname', str) Decklist = Counter[Cardname] USEFUL_SUPPLEMENTAL_SET_TYPES = ("reprint", "un", "commander", "planechase", "archenemy", "vanguard", "masters") ALL_SETS: list[Set] = Set.all() CORE_SETS: list[Set] = [set_ for set_ in ALL_SETS if set_.type == 'core'] EXPERT_SETS: list[Set] = [ set_ for set_ in ALL_SETS if set_.type == 'expansion' ] ALL_TRUE_SETS: list[Set] = CORE_SETS + EXPERT_SETS def sets_in(card_name: str): card = mtgsdk.Card.where(name=card_name).all() return card[0].printings.copy()
def get_all_sets(): return Set.all()
def print_cardset_names(): all_sets = Set.all() for mtgset in all_sets: print(mtgset.code, mtgset.name)
def get_set(): sets = Set.all() # Gets a list of all Sets return random.choice(sets) # returns a random Set object