pokemon.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. import requests
  3. import os
  4. browser = "palemoon"
  5. search = input("Pokemon: ").lower().replace(" ","-")
  6. data = requests.get("https://pokeapi.co/api/v2/pokemon?limit=2000").json()
  7. for pokemon in data["results"]:
  8. if search in pokemon["name"]:
  9. search = pokemon["name"].split("-")[0]
  10. search2 = pokemon["name"]
  11. else:
  12. print("ERROR: Either you mispelled or we couldn't find it")
  13. quit()
  14. data = requests.get(f"https://pokeapi.co/api/v2/pokemon-species/{search}/").json()
  15. data2 = requests.get(f"https://pokeapi.co/api/v2/pokemon/{search}/").json()
  16. types = []
  17. for type in data2["types"]:
  18. types.append(type["type"]["name"])
  19. types = ' | '.join(types)
  20. artwork = data2["sprites"]["other"]["official-artwork"]["front_default"]
  21. os.system(f"{browser} {artwork}")
  22. # This is not at all reliable
  23. chain = requests.get(data["evolution_chain"]["url"]).json()
  24. for evolution in chain["chain"]["evolves_to"]:
  25. evolves_to = evolution["species"]["name"]
  26. print(f"""From Generation: {data["generation"]["url"].split("/")[6]}
  27. Type: {types}""")