forked from mackorone/tidbyt-pokedex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokedex.star
43 lines (37 loc) · 1.25 KB
/
pokedex.star
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
load("http.star", "http")
load("render.star", "render")
load("time.star", "time")
NUM_POKEMON = 386
POKEAPI_URL = "https://pokeapi.co/api/v2/pokemon/{}"
def main():
id_ = int(NUM_POKEMON * random()) + 1
pokemon_url = POKEAPI_URL.format(id_)
pokemon = http.get(pokemon_url).json()
name = pokemon["name"].title()
height = str(pokemon["height"] / 10) + "m"
weight = str(pokemon["weight"] / 10) + "kg"
sprite_url = pokemon["sprites"]["versions"]["generation-vii"]["icons"]["front_default"]
sprite = http.get(sprite_url).body()
return render.Root(
child=render.Stack(
children=[
render.Row(
children=[
render.Box(width=32),
render.Box(render.Image(sprite)),
]
),
render.Column(
children=[
render.Text(name),
render.Text("# " + str(id_)),
render.Text(height),
render.Text(weight),
]
),
]
)
)
def random():
"""Return a pseudo-random number in [0, 1)"""
return time.now().nanosecond / (1000 * 1000 * 1000)