-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
45 lines (37 loc) · 1.19 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#################################################################################
#
# test.py
#
# Run this file to test the Pokemon class on every available Pokemon (1118 in
# total as of writing).
#
# Requirement: Please install the requests package by running
# pip install requests
#
#################################################################################
import requests
from time import time
from pokemon import get_pokemon
def main() -> None:
url = "https://pokeapi.co/api/v2/pokemon?limit=1200"
all_pokemons = requests.get(url).json()
num_pokemons = all_pokemons["count"]
print("Retrieved", num_pokemons, "pokemon names.")
i = 1
pct = 0.05
print("Retrieving data on these pokemons! This might take a while.")
start = time()
for pokemon_ in all_pokemons["results"]:
try:
get_pokemon(pokemon_["name"])
except Exception as e:
print("Got an error for the", str(i) + "-th Pokemon!")
print(e)
i += 1
if i / num_pokemons >= pct:
print(str(int(pct * 100)) + "%", "done.")
pct += 0.05
print("Done! Processed", num_pokemons, "pokemons in roughly", int(time() - start), "seconds.")
return None
if __name__ == '__main__':
main()