Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns hyperiums-cli.fury-api
- (:require [clj-http.client :as client]
- [jsonista.core :as j]))
- (def base-url "https://REDACTED")
- (defn game-url [game]
- (str base-url game "/"))
- (def hyp10-url (partial game-url "hyp10"))
- (defn planets-url [game-url]
- (str game-url "planets/"))
- (defn new-spawn-url [planets-url sc]
- (str planets-url "/new-spawn/" sc))
- (defn new-spawns [url]
- (let [resp (client/get url)]
- (get (j/read-value (:body resp)) "result")))
- (let [response (new-spawns (-> (hyp10-url)
- (planets-url)
- (new-spawn-url 3)))
- grouped-by-coordinate (group-by
- (juxt #(get % "planet_x") #(get % "planet_y"))
- response)
- coords (keys grouped-by-coordinate)
- example-coord (first coords)
- planets-at-example (get grouped-by-coordinate example-coord)]
- ["Example coords: " example-coord
- "New planets at example coords: " (map #(select-keys % ["planet_gov" "planet_race" "planet_name"]) planets-at-example)])
- ;; => ["Example coords: "
- ;; [-7 -8]
- ;; "New planets at example coords: "
- ;; ({"planet_gov" "Prot", "planet_race" "H", "planet_name" "Berrantryke"}
- ;; {"planet_gov" "Auth", "planet_race" "H", "planet_name" "Neutral-M3-1I"}
- ;; {"planet_gov" "Auth", "planet_race" "A", "planet_name" "Neutral-5RE-1H"})]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement