Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Subsea cable map

submarinecables.livemd

Subsea cable map

Mix.install([
  {:req, "~> 0.5.8"}
])

Section

search = Req.get!("https://www.submarinecablemap.com/api/v3/search.json").body
cable_ids =
  search
  |> Enum.reduce(MapSet.new(), fn %{"url" => url}, acc ->
    paths = url |> String.split("/")
      if Enum.at(paths, 1) == "submarine-cable" do
         MapSet.put(acc, Enum.at(paths, 2))
      else
        acc
      end
  end)
  |> Enum.to_list()
  |> Enum.sort()
cables = 
  cable_ids
  |> Task.async_stream(fn cid -> 
    Req.get!("https://www.submarinecablemap.com/api/v3/cable/#{cid}.json").body
  end)
  |> Enum.map(fn {:ok, result} -> result end)
cables_geo = Req.get!("https://www.submarinecablemap.com/api/v3/cable/cable-geo.json").body
cables_geo |> Map.get("features") |> hd()
landin_points = Req.get!("https://www.submarinecablemap.com/api/v3/landing-point/landing-point-geo.json").body
landin_points |> Map.get("features") |> hd()