def test_requests_errors(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        body=requests.exceptions.RequestException("Some error"),
    )

    with pytest.raises(PyPokedexError):
        pypokedex.get(name="sample")
def test_other_HTTP_errors(responses):
    responses.add(responses.GET,
                  "https://pokeapi.co/api/v2/pokemon/sample",
                  json={},
                  status=408)

    with pytest.raises(PyPokedexHTTPError) as other_http_error:
        pypokedex.get(name="sample")

    assert other_http_error.value.http_code == 408
def test_404_pokemon_not_found(responses):
    responses.add(responses.GET,
                  "https://pokeapi.co/api/v2/pokemon/sample",
                  json={},
                  status=404)

    with pytest.raises(PyPokedexHTTPError) as not_found:
        pypokedex.get(name="sample")

    assert not_found.value.http_code == 404
def test_missing_data_keys_for_pokemon(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    del cloned_sample_pokemon["weight"]
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=cloned_sample_pokemon,
        status=200,
    )

    with pytest.raises(PyPokedexError):
        pypokedex.get(name="sample")
Beispiel #5
0
async def find(ctx,*,pokemon_name):
    pokemon = pypokedex.get(name=pokemon_name)
    http = urllib3.PoolManager()
    response = http.request('GET', pokemon.sprites.front.get('default'))
    image = PIL.Image.open(BytesIO(response.data))
    img = image.save("pokemon.png")
    await ctx.send(f"{pokemon_name} found!")
    with open("pokemon.png","rb") as fp:
        print("All is working good")

    type_pokemon = pokemon.types
    res = str(type_pokemon)[1:-1]

    filePath = discord.File("C:/Users/shankar/OneDrive/Desktop/shanmukha/Python/Discord/pokemon.png", filename = "pokemon.png")

    embed = discord.Embed(color = discord.Color.blue())
    embed.add_field(name = f"**__{pokemon.name}__**", value = f"Showing Stats for {pokemon.name}", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Pokedex number**: ``{pokemon.dex}``", inline=False)
    embed.add_field(name = f"\u200b", value = f"**Types**: ``{res}``",inline=False)
    embed.add_field(name = f"\u200b",value = f"**HP**: ``{pokemon.base_stats.hp}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Attack**: ``{pokemon.base_stats.attack}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Defence**: ``{pokemon.base_stats.defense}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Special Attack**: ``{pokemon.base_stats.sp_atk}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Special Defence**: ``{pokemon.base_stats.sp_def}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Height**: ``{pokemon.height*10}``", inline=False)
    embed.add_field(name = f"\u200b",value = f"**Weight**: ``{pokemon.weight/10}``", inline=False)

    embed.set_image(url = "attachment://pokemon.png")
    embed.set_thumbnail(url = ctx.author.avatar_url)
    await ctx.send(file = filePath,embed=embed)
Beispiel #6
0
    async def pokedex(self, ctx, pokemon):
        try:
            pokemon = pypokedex.get(name=pokemon)
            base_abilities = []
            base_stats = []
            pokemon_types = []
            sprite = pokemon.sprites

            for abilities in pokemon.abilities:
                base_abilities.append(abilities.name)
            for stats in pokemon.base_stats:
                # all values are initially grabbed as ints
                base_stats.append(str(stats))
            for types in pokemon.types:
                pokemon_types.append(types)

            embed = discord.Embed(title="Who's that pokemon?", description="It's {0}, bitch".format(pokemon.name.capitalize()),
                                  color=discord.Color.dark_grey())
            embed.set_thumbnail(url=sprite.front["default"])
            embed.add_field(name="Abilities:", value=', '.join(base_abilities), inline=False)
            embed.add_field(name="Height:", value=str(pokemon.height) + 'ft', inline=False)
            embed.add_field(name="Weight:", value=str(pokemon.weight) + 'lb(s)', inline=False)

            embed.add_field(name="HP:", value=base_stats[0], inline=True, )
            embed.add_field(name="Atk:", value=base_stats[1], inline=True, )
            embed.add_field(name="Def:", value=base_stats[2], inline=True, )
            embed.add_field(name="Sp Atk:", value=base_stats[3], inline=True, )
            embed.add_field(name="Sp Def:", value=base_stats[4], inline=True, )
            embed.add_field(name="Speed:", value=base_stats[5], inline=True, )

            embed.add_field(name="Type(s): ", value=','.join(pokemon_types), inline=False)

            await ctx.send(embed=embed)
        except:
            await ctx.send("That pokemon doesn't exist")
Beispiel #7
0
 async def on_message(self, message):
     ratelimit = self.get_ratelimit(message)
     if (message.author.bot) or ratelimit is None:
         return
     else:
         pokemon_name = randnum('Coding Files/Python/PokeBot/pokemon.txt')
         print(f"Pokemon Name : {pokemon_name}")
         pokemon = pypokedex.get(name=pokemon_name)
         http = urllib3.PoolManager()
         response = http.request('GET', pokemon.sprites.front.get('default'))
         image = PIL.Image.open(BytesIO(response.data))
         img = image.save("pokemon.png")
         with open("pokemon.png","rb") as fp:
             await message.channel.send(file = discord.File(fp, "pokemon.png"))
         
         await message.channel.send("Whos that pokemon")
         try:
             msg = await self.client.wait_for(
                 "message",
                 timeout=10,
                 check=lambda m : m.author == message.author and m.channel == message.channel
             )
             if msg.content.lower() == pokemon_name:
                 await message.channel.send("You guessed it correct! :partying_face:")
         except asyncio.TimeoutError:
             await message.channel.send("Ouch! that pokemon name is {}".format(pokemon_name))
def test_pokemon_equality(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(name="sample")
    second_pokemon = pypokedex.get(dex=999)
    assert first_pokemon == second_pokemon
def test_pokemon_inequality(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    assert first_pokemon != second_pokemon
def test_pokemon_str_function(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")
    assert str(pokemon) == "Pokemon(dex=999, name='sample')"
def test_get_pokemon_by_name(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert _is_properly_initialized_pokemon(pokemon)
def test_pokemon_does_not_learn_move(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert not pokemon.learns("random move", "game_1")
def test_pokemon_existence_in_games(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert pokemon.exists_in("game_1")
def test_get_pokemon_by_dex(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(dex=999)

    assert _is_properly_initialized_pokemon(pokemon)
def test_pokemon_greater_than(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    assert second_pokemon > first_pokemon
    assert not second_pokemon == first_pokemon
    assert not second_pokemon < first_pokemon
Beispiel #16
0
def load_pokemon():
    pokemon = pypokedex.get(name=text_id_name.get(1.0, "end-1c"))

    http = urllib3.PoolManager()
    response = http.request("GET", pokemon.sprites.front.get("default"))
    image = PIL.Image.open(BytesIO(response.data))

    img = PIL.ImageTk.PhotoImage(image)
    pokemon_image.config(image=img)
    pokemon_image.image = img

    pokemon_info.config(text=f"Nr.{pokemon.dex}  {pokemon.name}")
    pokemon_type.config(text=f"{pokemon.types}")
Beispiel #17
0
def load():
    pokemon = pyp.get(name=text.get(1.0, "end-1c"))

    http = urllib3.PoolManager()
    response = http.request('GET', pokemon.sprites.front.get('default'))
    image = PIL.Image.open(BytesIO(response.data))

    img = PIL.ImageTk.PhotoImage(image)
    pokemonImage.config(image=img)
    pokemonImage.image = img

    info.config(text=f"{pokemon.dex} - {pokemon.name}")
    types.config(text=f"{pokemon.types}")
def test_pokemon_less_than_or_equal_to(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    third_pokemon = pypokedex.get(dex=999)
    assert first_pokemon <= second_pokemon
    assert second_pokemon <= third_pokemon
    assert not third_pokemon <= first_pokemon
def test_pokemon_does_not_learn_move_because_it_is_not_in_the_specified_game(
        responses):  # noqa
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    with pytest.raises(PyPokedexError):
        pokemon.learns("random move", "random game")
Beispiel #20
0
def load_pokemon():
    pokemon = pypokedex.get(name=text_id_name.get(1.0, "end-1c"))

    http = urllib3.PoolManager()
    response = http.request('GET', pokemon.sprites.front.get('default'))
    image = PIL.Image.open(BytesIO(response.data))

    img = PIL.ImageTk.PhotoImage(image)
    pokemon_image.config(image=img)
    pokemon_image.image = img

    pokemon_information.config(text=f"{pokemon.dex} - {pokemon.name}")
    pokemon_types.config(text=" - ".join([t for t in pokemon.types]).title())
Beispiel #21
0
 async def search(self, ctx, pokemon, special=None):
     try:
         p = pypokedex.get(name=pokemon)
     except TypeError:
         await ctx.send("That pokemon Does not exist.")
     if special == None:
         embed = discord.Embed(title = f"**__Showing stats for {pokemon}__**", url = f"https://pokemondb.net/pokedex/{pokemon}", color = discord.Color.blue())
         embed.add_field(name="Pokemon Dex Index : ", value = f"{p.dex}", inline= False)
         embed.add_field(name="Pokemon Weight : ", value = f"``{p.weight/10}``", inline = False)
         embed.add_field(name="Pokemon Height : ", value = f"``{p.height*10}``", inline = False)
         embed.set_thumbnail(icon_url=ctx.author.avatar_url)
         # embed.add_field(name = "Something", value = (discord.File('pokemon.png')), inline=False)
         embed.set_image(url="pokemon.png")
         await ctx.send(embed=embed)
Beispiel #22
0
def load_pokemon():
     pokemon=pypokedex.get(name=text_idname.get(1.0,"end-1c"))
     #end-1c is to ignore \n in the string
     http=urllib3.PoolManager()
     response=http.request('GET',pokemon.sprites.front.get('default'))
     image=PIL.Image.open(BytesIO(response.data))
     #putting the pokemon image into a pillow object

     img=PIL.ImageTk.PhotoImage(image)
     #putiing the object into tkinter 
     pokemon_image.config(image=img)
     pokemon_image.image=img 
     
     poke_info.config(text=f"{pokemon.dex} - {pokemon.name}")
     poke_types.config(text=" , ".join([type for type in pokemon.types]))
Beispiel #23
0
def load_pokemon():
    pokemon = pypokedex.get(name=text_id_name.get(1.0, 'end-1c'))

    #get sprites mentioned above in thriple inverted commas
    http = urllib3.PoolManager()
    response = http.request('GET', pokemon.sprites.front.get('default'))

    #turn the image in response to Bytes then into pillow
    image = PIL.Image.open(BytesIO(response.data))

    #put image into tkinter
    img = PIL.ImageTk.PhotoImage(image)
    pokemon_image.config(image=img)
    pokemon_image.image = img

    pokemon_information.config(text=f"{pokemon.dex} - {pokemon.name}")
    pokemon_types.config(
        text=",".join(pokemon.types)
    )  #join used to make it look more real rather than programmy
Beispiel #24
0
def LoadPokemon(value):
    #New Window
    new_screen = Toplevel()
    new_screen.geometry('620x400')

    #get pokemon
    pokemon = pypokedex.get(name=value)

    #GET IMAGE
    http = urllib3.PoolManager()
    response = http.request('GET', pokemon.sprites.front.get('default'))
    image = PIL.Image.open(BytesIO(response.data))

    #pokemon Information
    pokemon_img = Label(new_screen)
    pokemon_information = Label(new_screen,
                                text=f'{pokemon.dex} - {pokemon.name}',
                                font=('Arial', 12))
    pokemon_type = Label(new_screen,
                         text=f'Type: {pokemon.types}',
                         font=('Arial', 12))
    pokemon_baseStats = Label(new_screen,
                              text=f'{pokemon.base_stats}',
                              font=('Arial', 12))
    pokemon_weight = Label(new_screen,
                           text=f'Weight: {pokemon.weight}',
                           font=('Arial', 12))
    pokemon_height = Label(new_screen,
                           text=f'Height: {pokemon.height}',
                           font=('Arial', 12))

    #POSITIONS
    pokemon_information.place(x=0, y=120)
    pokemon_type.place(x=0, y=150)
    pokemon_baseStats.place(x=0, y=180)
    pokemon_weight.place(x=0, y=210)
    pokemon_height.place(x=0, y=235)
    pokemon_img.place(x=120, y=30)

    #Put image
    img = PIL.ImageTk.PhotoImage(image)
    pokemon_img.config(image=img)
    pokemon_img.image = img
Beispiel #25
0
def load_pokemon():
    try:
        # getting the pokemon object
        pokemon = pypokedex.get(name=text_id_name.get(1.0, "end-1c"))

        # loading and diplaying the image
        http = urllib3.PoolManager()
        response = http.request('GET', pokemon.sprites.front.get("default"))
        image = PIL.Image.open(BytesIO(response.data))
        img = PIL.ImageTk.PhotoImage(image)
        pokemon_image.config(image=img)
        pokemon_image.image = img

        # displaying other infos
        pokemon_info.config(text=f"{pokemon.dex} - {pokemon.name}".title())
        pokemon_types.config(text="Type: " +
                             " , ".join([t for t in pokemon.types]).title())
        pokemon_ability.config(
            text="Abilities: " +
            " , ".join([a.name for a in pokemon.abilities]).title())

    # handling the excetion in case some one entered the wrong name or index
    except Exception as e:
        pokemon_info.config(text=e)
def test_too_few_get_arguments():
    with pytest.raises(TypeError):
        pypokedex.get()
def test_too_many_get_arguments():
    with pytest.raises(TypeError):
        pypokedex.get(a=2, b="many", dex="arguments")
Beispiel #28
0
import pypokedex
p = pypokedex.get(dex=45)
print(p.name)
# print(p.moves)
def test_incorrect_get_argument_types():
    with pytest.raises(TypeError):
        pypokedex.get(dex="A STRING")

    with pytest.raises(TypeError):
        pypokedex.get(name=111)
    ], [sg.Button('Ok'), sg.Button('Cancel')]
]

window = sg.Window('Pokemon Star-Dust Calculator', layout)

# Event Loop to process "events" and get the "values" of the inputs
while True:

    event, values = window.read()
    if event in (None, 'Cancel'):  # if user closes window or clicks cancel
        break
    #print('You entered ', values[0])

    #print("Please input the name of the Pokemon you're comparing:")
    x = values[0]
    p = pypokedex.get(name=str(x))
    stat_calculations(p)
    #print('Enter the current CP of the High CP/Low IV Pokemon')
    high_cp = int(values[1])

    #print('Now enter the IVs of your Pokemon in the order: |Stamina| |Attack| |Defense| ')
    CP_high_list = list(
        compute_cp(int(values[2]), int(values[3]), int(values[4])).values())

    #print('Please enter the current CP of the Low CP/High IV Pokemon: ')
    low_cp = int(values[5])

    #print('Now enter the IVs of that Pokemon in the order: |Stamina| |Attack| |Defense| ')
    CP_low_list = list(
        compute_cp(int(values[6]), int(values[7]), int(values[8])).values())