def getCard(self, cardSet, cardNum): """ :param cardSet: Name of the set the card is in :param cardNum: number of the card in the set :return: Card object with all card attributes """ return Card.find(id=f"{self.setDict[cardSet].lower()}-{str(cardNum)}")
def get_cards(format): get_sets() sets = req_format(format) check_path() h = open('archive/cards/hashed_cards.txt', "r") check = h.read().splitlines() h.close() for set in sets: print(set['name']) count = 1 for card in range(set['size']): try: req = str(set['req_id'] + '-' + str(count)) raw_card = str(Card.find(req)) card = strip_card(raw_card, count, set['id']) if(card['hash'] in check): print('found redundant card | skipping set') break save_card(card) print(set['id'], count,"| saved to", card['supertype'],"|", card['hash'], "|", card['name']) count +=1 except: print("req error | probaly a promo set") time.sleep(2) break print()
def parse_card(name, card_set): # If the card set includes a specific number, we can just use that to # get the card card = None if "-" in card_set: card = Card.find(card_set) if card == None: return "No results for card `%s`" % card_set else: # Search for the given card cards = Card.where(name = name, setCode=card_set) if len(cards) == 0: return ("No results found for '%s' in set `%s`" % (name, card_set)) if len(cards) > 1: return ( """ Too many results. Try specifying the card number too. For example `!show %s %s-%s` """ % (name, card_set, cards[0].number) ) card = cards[0] return card
def test_find_returns_card(self): with vcr.use_cassette('fixtures/gardevoir.yaml'): card = Card.find('xy7-54') self.assertEqual('xy7-54', card.id) self.assertEqual('Gardevoir', card.name) self.assertEqual('Pokémon', card.supertype) self.assertEqual(['Stage 2'], card.subtypes) self.assertEqual('130', card.hp) self.assertEqual(['Fairy'], card.types) self.assertEqual('Kirlia', card.evolvesFrom) self.assertTrue(len(card.abilities) == 1) self.assertTrue(len(card.attacks) == 1) self.assertTrue(len(card.weaknesses) == 1) self.assertTrue(len(card.resistances) == 1) self.assertEqual(['Colorless', 'Colorless'], card.retreatCost) self.assertEqual(2, card.convertedRetreatCost) self.assertEqual('xy7', card.set.id) self.assertEqual('54', card.number) self.assertEqual('TOKIYA', card.artist) self.assertEqual('Rare Holo', card.rarity) self.assertEqual( 'It has the power to predict the future. Its power peaks when it is protecting its Trainer.', card.flavorText) self.assertEqual([282], card.nationalPokedexNumbers) self.assertEqual('https://prices.pokemontcg.io/tcgplayer/xy7-54', card.tcgplayer.url)
def test_find_returns_card(self): with vcr.use_cassette('fixtures/gardevoir.yaml'): card = Card.find('xy7-54') self.assertEqual('Gardevoir', card.name) self.assertEqual('xy7-54', card.id) self.assertEqual(282, card.national_pokedex_number) self.assertEqual('https://s3.amazonaws.com/pokemontcg/xy7/54.png', card.image_url) self.assertEqual('Stage 2', card.subtype) self.assertEqual('Pokémon', card.supertype) self.assertEqual('Bright Heal', card.ability['name']) self.assertEqual( 'Once during your turn (before your attack), you may heal 20 damage from each of your Pokémon.', card.ability['text']) self.assertEqual('130', card.hp) self.assertEqual(['Colorless', 'Colorless'], card.retreat_cost) self.assertEqual('54', card.number) self.assertEqual('TOKIYA', card.artist) self.assertEqual('Rare Holo', card.rarity) self.assertEqual('XY', card.series) self.assertEqual('Ancient Origins', card.set) self.assertEqual('xy7', card.set_code) self.assertEqual(['Fairy'], card.types) self.assertTrue(len(card.attacks) == 1) self.assertTrue(len(card.weaknesses) == 1) self.assertTrue(len(card.resistances) == 1)
def test_find_returns_card(self): with vcr.use_cassette('fixtures/gardevoir.yaml'): card = Card.find('xy7-54') self.assertEqual('Gardevoir', card.name) self.assertEqual('xy7-54', card.id) self.assertEqual(282, card.national_pokedex_number) self.assertEqual('https://images.pokemontcg.io/xy7/54.png', card.image_url) self.assertEqual('Stage 2', card.subtype) self.assertEqual('Pokémon', card.supertype) self.assertEqual('Bright Heal', card.ability['name']) self.assertEqual('Once during your turn (before your attack), you may heal 20 damage from each of your Pokémon.',card.ability['text']) self.assertEqual('130', card.hp) self.assertEqual(['Colorless', 'Colorless'], card.retreat_cost) self.assertEqual(2, card.converted_retreat_cost) self.assertEqual('54', card.number) self.assertEqual('TOKIYA', card.artist) self.assertEqual('Rare Holo', card.rarity) self.assertEqual('XY', card.series) self.assertEqual('Ancient Origins', card.set) self.assertEqual('xy7', card.set_code) self.assertEqual(['Fairy'], card.types) self.assertTrue(len(card.attacks) == 1) self.assertTrue(len(card.weaknesses) == 1) self.assertTrue(len(card.resistances) == 1)
def parse_card(name, card_set): # If the card set includes a specific number, we can just use that to # get the card card = None if "-" in card_set: card_part = card_set.split("-") for set_code, setid in sets.items(): if set_code in card_set: card_set = card_set.replace(card_part[0], setid.lower()) card = Card.find(card_set) if card is None: return "No results for card `%s`" % card_set else: # Check if a Set Abbreviation was used instead nums = set('0123456789') for set_code, setid in sets.items(): card_set = card_set.replace(set_code, setid) # Verify Set Abbreviation was replaced if any((n in nums) for n in card_set): # Search for the given card cards = Card.where(q=f'name:{name} set.id:{card_set}') if len(cards) == 0: return "No results found for '%s' in set `%s`" % (name, card_set) if len(cards) > 1: return ("Too many results. Try specifying the card number too. " "For example `[p]show %s %s-%s`" % (name, card_set, cards[0].number)) card = cards[0] else: return ("Set Abbreviation wasn't found. Double check and try again.") return card
def show(self, card_id: str) -> Optional[ShowResult]: """ Get details on a specific card. :param card_id: The unique ID on the card :returns: The result of the card lookup, or None if no card matches """ card = Card.find(card_id) card_set = Set.find(card.set_code) if not card: return None if card.supertype == "Pokémon": fields = [] # If the Pokemon has an ability, it goes in its own field if card.ability: fields.append( (f"{card.ability['type']}: {card.ability['name']}", card.ability["text"] or "\u200b")) # Each attack is its own field if card.attacks: for attack in card.attacks: name = "" text = "" for cost in attack["cost"]: name += emoji[cost] name += f" {attack['name']}" if "damage" in attack and attack["damage"] != "": name += f" - {attack['damage']}" if "text" in attack and attack["text"] != "": text = attack["text"] else: text = "\u200b" fields.append((name, text)) # Weakness, resistances and retreat all go on the same line bottom_line = "" if card.weaknesses: bottom_line += "Weakness: " bottom_line += ", ".join([ f"{emoji[w['type']]} ({w['value']})" for w in card.weaknesses ]) if card.resistances: bottom_line += " - Resistance: " bottom_line += ", ".join([ f"{emoji[r['type']]} ({r['value']})" for r in card.resistances ]) if card.retreat_cost: bottom_line += f" - Retreat: {emoji['Colorless'] * len(card.retreat_cost)}" if bottom_line != "": fields.append(("\u200b", bottom_line)) return ShowResult( name=card.name, supertype=card.supertype, subtype=card.subtype, legality=PokemonTCGIOV1Provider._newest_legal_format(card), set_name=card_set.name, set_no=card.number, set_max=card_set.total_cards, image=card.image_url, set_icon=card_set.symbol_url, fields=fields, hp=card.hp, evolves_from=card.evolves_from, types=card.types) else: return ShowResult( name=card.name, supertype=card.supertype, subtype=card.subtype, legality=PokemonTCGIOV1Provider._newest_legal_format(card), set_name=card_set.name, set_no=card.number, set_max=card_set.total_cards, image=card.image_url, set_icon=card_set.symbol_url, fields=[("\u200b", text) for text in card.text])
def getAllCards(): ## Card.where(page=5, pageSize=100) card = Card.find('xy1-1') name = card.name print(name) return ('', 200)
def show(name, card_set): # If the card set includes a specific number, we can just use that to # get the card card = None if "-" in card_set: card = Card.find(card_set) if card == None: return "No results for card `%s`" % card_set else: # Search for the given card cards = Card.where(name = name).where(setCode=card_set).all() if len(cards) == 0: return ("No results found for '%s' in set `%s`" % (name, card_set)) if len(cards) > 1: return ( """ Too many results. Try specifying the card number too. For example `!show %s %s-%s` """ % (name, card_set, cards[0].number) ) card = cards[0] # Create a string for the card text return_str = "%s\n" % card.image_url return_str += "```\n" # Pokemon are the most involved as they have a lot going on if card.supertype == "Pokémon": # Start with the Pokemon's name and type(s) return_str += "%s - %s" % (card.name, "/".join(card.types)) # Some Pokemon have no HP (e.g. the second half of LEGEND cards), # so do only add it if it exists if card.hp != None: return_str += " - HP%s\n" % (card.hp) else: return_str += "\n" return_str += "%s Pokemon\n\n" % card.subtype # Add the ability if present if card.ability != None: return_str += "%s: %s\n" % (card.ability['type'], card.ability['name']) return_str += "%s\n" % card.ability['text'] return_str += "\n" # Add any attacks, including shorthand cost, text and damage if card.attacks != None: for attack in card.attacks: for cost in attack['cost']: return_str += "%s" % short_energy[cost] return_str += " %s" % attack['name'] if attack['damage'] != '': return_str += ": %s damage\n" % attack['damage'] else: return_str += "\n" if attack['text'] != None: return_str += "%s\n" % attack['text'] return_str += "\n" # Add weakness, resistances and retreat if they exist if card.weaknesses != None: for weakness in card.weaknesses: return_str += ("Weakness: %s (%s)\n" % (weakness['type'], weakness['value'])) if card.resistances != None: for resistance in card.resistances: return_str += ("Resistance: %s (%s)\n" % (resistance['type'], resistance['value'])) if card.retreat_cost != None: return_str += "Retreat: %s" % len(card.retreat_cost) # Trainers and Energy are a lot easier elif card.supertype == "Trainer" or card.supertype == "Energy": return_str += "%s\n" % card.name return_str += "%s\n\n" % card.subtype return_str += "%s\n" % "\n\n".join(card.text) # Finally, get the set and legality info card_set = Set.find(card.set_code) return_str += "\n\n%s - %s/%s" % (card_set.name, card.number, card_set.total_cards) if card_set.standard_legal == True: return_str += " (Standard)" elif card_set.expanded_legal == True: return_str += " (Expanded)" else: return_str += " (Legacy)" return_str += "```\n" return return_str