def test_get_pokemon(tmp_path): from pokemon.master import get_pokemon with pytest.raises(SystemExit): catch = get_pokemon(name="doesntexist") catch = get_pokemon(name="Pikachu") assert "25" in catch for param in [ "abilities", "ascii", "height", "id", "link", "name", "type", "weight", ]: assert param in catch["25"] assert str(catch["25"]["id"]) == "25" # These should return same pokemon repeat = get_pokemon(pid="25") assert repeat == catch repeat = get_pokemon(pid=25) assert repeat == catch
def main(): parser = argparse.ArgumentParser( description="generate pokemon ascii art and avatars") parser.add_argument("--avatar", dest='avatar', help="generate a pokemon avatar.", type=str, default=None) parser.add_argument("--pokemon", dest='pokemon', help="generate ascii for a particular pokemon (by name)", type=str, default=None) parser.add_argument("--message", dest='message', help="add a custom message to your ascii!", type=str, default=None) parser.add_argument('--catch', help="catch a random pokemon!", dest='catch', default=False, action='store_true') parser.add_argument('--list', help="list pokemon available", dest='list', default=False, action='store_true') try: args = parser.parse_args() except: parser.print_help() sys.exit(0) if args.list is True: names = catch_em_all(return_names=True) print("\n".join(names)) elif args.pokemon is not None: get_ascii(name=args.pokemon, message=args.message) # If the user wants to create an avatar elif args.avatar != None: get_avatar(args.avatar) elif args.catch == True: catch = get_pokemon() pid = list(catch.keys())[0] get_ascii(pid=pid, message=args.message) else: parser.print_help()
def catch_pokemon(): '''use the get_pokemon function to catch a random pokemon, return it (along with stats!) as a single string ''' catch = get_pokemon() for pokemon_id, meta in catch.items(): response = meta['ascii'] response = "%s\n%s %s" % (response, meta["name"], meta['link']) print(response)
def generate_pokemon(pid): """Generate a pokemon based on a particular identifier. This is excessive because we could just use get_pokemon() to return a random pokemon, but we are taking in the pid (pokemon id) as an example for providing a function to generate input arguments for a gridtest. """ catch = get_pokemon(pid=pid) catch_id = list(catch.keys())[0] return catch[catch_id]["ascii"]
def main(): parser = argparse.ArgumentParser( description="generate pokemon ascii art and avatars") parser.add_argument("--avatar", dest='avatar', help="generate a pokemon avatar.", type=str, default=None) parser.add_argument( "--pokemon", dest='pokemon', help="generate ascii for a particular pokemon (by name)", type=str, default=None) parser.add_argument("--message", dest='message', help="add a custom message to your ascii!", type=str, default=None) parser.add_argument('--catch', help="catch a random pokemon!", dest='catch', default=False, action='store_true') parser.add_argument('--list', help="list pokemon available", dest='list', default=False, action='store_true') try: args = parser.parse_args() except: parser.print_help() sys.exit(0) if args.list is True: names = catch_em_all(return_names=True) print("\n".join(names)) elif args.pokemon is not None: get_ascii(name=args.pokemon, message=args.message) # If the user wants to create an avatar elif args.avatar != None: get_avatar(args.avatar) elif args.catch == True: catch = get_pokemon() pid = list(catch.keys())[0] get_ascii(pid=pid, message=args.message) else: parser.print_help()
async def get(self) -> Tuple[str, BytesIO, BytesIO]: pokemon = list(get_pokemon(pokemons=pokemons).values())[0] res = await self.bot.session.get( f"https://gearoid.me/pokemon/images/artwork/{pokemon.id}.png") original_img = BytesIO(await res.read()) black_img = BytesIO() image = Image.open(deepcopy(original_img)) enh = ImageEnhance.Brightness(image) enh.enhance(0).save(black_img, "PNG") black_img.seek(0) return pokemon['name'], original_img, black_img
def get_ascii(pid=None, name=None, pokemons=None, return_pokemons=False, message=None): '''get_ascii will return ascii art for a pokemon based on a name or pid. :param pid: the pokemon ID to return :param name: the pokemon name to return :param return_pokemons: return catches (default False) :param message: add a message to the ascii ''' pokemon = get_pokemon(name=name,pid=pid,pokemons=pokemons) printme = message if len(pokemon) > 0: for pid,data in pokemon.items(): if message == None: printme = data["name"].capitalize() print("%s\n\n%s" % (data['ascii'],printme)) if return_pokemons == True: return pokemon
def get_avatar(name, pokemons=None, print_screen=True, include_name=True): """get_avatar will return a unique pokemon for a specific avatar based on the hash :param name: the name to look up :param print_screen: if True, will print ascii to the screen (default True) and not return :param include_name: if True, will add name (minus end of address after @) to avatar """ if pokemons is None: pokemons = catch_em_all() # The IDs are numbers between 1 and the max number_pokemons = len(pokemons) trainer = get_trainer(name) pid = str(trainer % number_pokemons) pokemon = get_pokemon(pid=pid, pokemons=pokemons) avatar = pokemon[pid]["ascii"] if include_name is True: avatar = "%s\n\n%s" % (avatar, name.split("@")[0]) if print_screen is True: print(avatar) return avatar
def get_avatar(name, pokemons=None, print_screen=True, include_name=True): '''get_avatar will return a unique pokemon for a specific avatar based on the hash :param name: the name to look up :param print_screen: if True, will print ascii to the screen (default True) and not return :param include_name: if True, will add name (minus end of address after @) to avatar ''' if pokemons is None: pokemons = catch_em_all() # The IDs are numbers between 1 and the max number_pokemons = len(pokemons) trainer = get_trainer(name) pid = str(trainer % number_pokemons) pokemon = get_pokemon(pid=pid,pokemons=pokemons) avatar = pokemon[pid]["ascii"] if include_name is True: avatar = "%s\n\n%s" %(avatar,name.split("@")[0]) if print_screen is True: print(avatar) return avatar