From f116fd9bab865cf55b7a39e5b7710a7ce401c55d Mon Sep 17 00:00:00 2001 From: tA Date: Wed, 16 Oct 2019 15:00:42 +1300 Subject: [PATCH] week5 is hard --- 201/week5/poke.hoon | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 201/week5/poke.hoon diff --git a/201/week5/poke.hoon b/201/week5/poke.hoon new file mode 100644 index 0000000..b3e91dd --- /dev/null +++ b/201/week5/poke.hoon @@ -0,0 +1,53 @@ +/+ tapp, stdio +:: +=> + |% + +$ state + $: pokedex=(map cord json) + == + +$ peek-data _!! + +$ in-poke-data [%noun =cord] + +$ out-poke-data ~ + +$ in-peer-data ~ + +$ out-peer-data + $% [%pokemon json] + == + ++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data) + ++ stdio (^stdio out-poke-data out-peer-data) + -- +=> + |% + ++ comment-to-tang + |= =tape + ^- tang + %+ welp + %+ turn (rip 10 (crip tape)) + |= line=cord + leaf+(trip line) + [leaf+""]~ + ++ urls + =/ base "https://pokeapi.co/api/v2/" + :* pokemon=(weld base "pokemon/") + == + -- +=, async=async:tapp +=, tapp-async=tapp-async:tapp +=, stdio +:: +%- create-tapp-poke-peer-take:tapp +^- tapp-core-poke-peer-take:tapp +|_ [=bowl:gall state] +:: +++ handle-poke + |= =in-poke-data + =/ m tapp-async + =/ pokename cord.in-poke-data + ^- form:m + :: + ?: (~(has by state) pokename) + ~& 'pokemon already caught' + (pure:m (~(got by state) pokename)) + =/ pokeurl (weld pokemon:urls (trip pokename)) + %+ (set-timeout _json) (add now.bowl ~s15) + ;< =json bind:m (fetch-json pokeurl) +