def get_sets(): global all_sets sets = Set.all() all_sets = [] for set in sets: raw_set = str(set).replace('Set', '').replace('=', '').replace('(', '').replace(')', '').replace("'",'').split(',') if(raw_set[5] == ' standardLegal'): format = 'standard' elif(raw_set[4] == ' expandedLegal'): format = 'expanded' else: format = 'unlimited' this_set = { 'id' : raw_set[8].replace('ptcgoCode','').replace(' ', '', 1), 'name' : raw_set[6].replace('name', '').replace(' ', '', 1), 'format' : format, 'size' : int(raw_set[-2].replace('total', '')), 'req_id' : raw_set[0].replace('id', '').replace(' ', '', 1), 'cards' : [] } all_sets.append(this_set)
def getAllSetIds(self): """ Gets all card set names and corresponding codes :return: Prints list of sets to console """ allCardSets = Set.all() cardSetName = [sets.name for sets in allCardSets] cardSetCode = [sets.code for sets in allCardSets] self.setDict = { cardSetName[i].lower(): cardSetCode[i] for i in range(len(cardSetName)) }
def main(): print("Downloading all cards... Please be patient") fields_remain_same = [ 'id', 'name', 'national_pokedex_number', 'image_url', 'image_url_hi_res', 'subtype', 'supertype', 'hp', 'number', 'artist', 'rarity', 'series', 'set', 'set_code', 'converted_retreat_cost', 'evolves_from' ] set_fields = [ 'total_cards', 'standard_legal', 'expanded_legal', 'release_date' ] cards = Card.all() sets = Set.all() create_workbook(cards, fields_remain_same, sets, set_fields)
def insert_cards(set_name): cards = Card.where(q='set.name:{}'.format(set_name)) sets = Set.all() sets_to_save = [] for set in sets: sets_to_save.append(PokemonCardSet(id=set.id, name=set.name)) overlap, inserted = _dedupe_and_insert(PokemonCardSet, sets_to_save) cards_to_save = [] for card in cards: cards_to_save.append( PokemonCard(id=card.id, name=card.name, set=PokemonCardSet.objects.get(id=card.set.id))) overlap, inserted = _dedupe_and_insert(PokemonCard, cards_to_save) return overlap, inserted
def initial_sets_input(): # add sets info on db sets = Set.all() db = conn.cursor() for pc_set in sets: name = pc_set.name code = pc_set.code ptcgo_code = pc_set.ptcgo_code series = pc_set.series total_cards = pc_set.total_cards # already in int standard_legal = str(pc_set.standard_legal) expanded_legal = str(pc_set.expanded_legal) release_date = parser.parse( pc_set.release_date).date() # only want date, not time updated_at = parser.parse(pc_set.updated_at) logo_url = pc_set.logo_url symbol_url = pc_set.symbol_url db.execute( '''insert into pokemon_cards_set( name, code, ptcgo_code, series, total_cards, standard_legal, expanded_legal, release_date, updated_at, logo_url, symbol_url) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)''', [ name, code, ptcgo_code, series, total_cards, standard_legal, expanded_legal, release_date, updated_at, logo_url, symbol_url ]) conn.commit()
def test_all_returns_all_sets(self): with vcr.use_cassette('fixtures/all_sets.yaml'): sets = Set.all() self.assertGreater(len(sets), 70)
def getSets(): sets= [(s.name,s.symbol_url) for s in Set.all()] return sets
def test_all_returns_all_sets(self): with vcr.use_cassette('fixtures/all_sets.yaml'): sets = Set.all() self.assertGreater(len(sets), 70)
from pokemontcgsdk import Set, Card from lxml import etree as et root = et.Element('cockatrice_carddatabase') root.attrib["version"] = "3" xmlsets = et.SubElement(root, "sets") xmlcards = et.SubElement(root, "cards") #Save sets for s in Set.all(): nset = et.SubElement(xmlsets, "set") name = et.SubElement(nset, "name") longname = et.SubElement(nset, "longname") setType = et.SubElement(nset, "setType") releasedate = et.SubElement(nset, "releasedate") name.text = s.code longname.text = s.name setType.text = s.series releasedate.text = s.release_date names = [] n = 0 for c in Card.all(): n += 1 ncard = et.SubElement(xmlcards, "card") name = et.SubElement(ncard, "name") cset = et.SubElement(ncard, "set") color = et.SubElement(ncard, "color") mana = et.SubElement(ncard, "manacost")
#! /usr/bin/env python from pokemontcgsdk import Card from pokemontcgsdk import Set from pokemontcgsdk import Type from pokemontcgsdk import Supertype from pokemontcgsdk import Subtype import json #Gets all info needed cards = Card.all() sets = Set.all() types = Type.all() subtypes = Subtype.all() supertypes = Supertype.all() print('Resources gathered, converting to json...') #Loops through all cards an eliminates all NoneTypes to eliminate excess null values in json cards_list = [] for c in cards: card_dict = {} if c.id is not None: card_dict["id"] = c.id if c.name is not None: card_dict["name"] = c.name if c.national_pokedex_number is not None: card_dict["national_pokedex_number"] = c.national_pokedex_number