Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns hyperiums-cli.fury-api
  2.   (:require [clj-http.client :as client]
  3.             [jsonista.core :as j]))
  4.  
  5. (def base-url "https://REDACTED")
  6.  
  7. (defn game-url [game]
  8.   (str base-url game "/"))
  9.  
  10. (def hyp10-url (partial game-url "hyp10"))
  11.  
  12. (defn planets-url [game-url]
  13.   (str game-url "planets/"))
  14.  
  15. (defn new-spawn-url [planets-url sc]
  16.   (str planets-url "/new-spawn/" sc))
  17.  
  18.  
  19. (defn new-spawns [url]
  20.   (let [resp (client/get url)]
  21.       (get (j/read-value (:body resp)) "result")))
  22.  
  23. (let [response (new-spawns (-> (hyp10-url)
  24.                                (planets-url)
  25.                                (new-spawn-url 3)))
  26.  
  27.       grouped-by-coordinate (group-by
  28.                              (juxt #(get % "planet_x") #(get % "planet_y"))
  29.                              response)
  30.       coords (keys grouped-by-coordinate)
  31.       example-coord (first coords)
  32.       planets-at-example (get grouped-by-coordinate example-coord)]
  33.   ["Example coords: " example-coord
  34.    "New planets at example coords: " (map #(select-keys % ["planet_gov" "planet_race" "planet_name"]) planets-at-example)])
  35.  
  36. ;; => ["Example coords: "
  37. ;;     [-7 -8]
  38. ;;     "New planets at example coords: "
  39. ;;     ({"planet_gov" "Prot", "planet_race" "H", "planet_name" "Berrantryke"}
  40. ;;      {"planet_gov" "Auth", "planet_race" "H", "planet_name" "Neutral-M3-1I"}
  41. ;;      {"planet_gov" "Auth", "planet_race" "A", "planet_name" "Neutral-5RE-1H"})]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement