File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
en-GB/lessons/Pokedex/Project Resources Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change 1
1
import io
2
2
import urllib .request
3
3
from urllib .request import urlopen
4
+ import ast
4
5
from PIL import Image , ImageTk
5
6
6
7
#function to get the data for a pokemon
7
8
def getPokemonData (num ):
8
9
data = urllib .request .urlopen ("http://pokeapi.co/api/v1/pokemon/" + str (num )).read ()
9
- pokemonDict = eval (data )
10
+ pokemonDict = ast . literal_eval (data . decode ( encoding = 'UTF-8' ) )
10
11
return pokemonDict
11
12
12
13
#function to get the image for a pokemon
13
14
def getPokemonImage (num ):
14
15
data = urllib .request .urlopen ("http://pokeapi.co/api/v1/sprite/" + str (num )).read ()
15
- spriteDict = eval (data )
16
+ spriteDict = ast . literal_eval (data . decode ( encoding = 'UTF-8' ) )
16
17
imgURL = "http://pokeapi.co" + spriteDict ["image" ]
17
18
image_bytes = urlopen (imgURL ).read ()
18
19
data_stream = io .BytesIO (image_bytes )
You can’t perform that action at this time.
0 commit comments