Created
May 13, 2018 13:59
-
-
Save tommyp/bfd977d8160f2606dd2d5988c7419313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Politics.Seeder.Countries do | |
alias Politics.Governments | |
def populate do | |
url = "https://raw.githubusercontent.com/everypolitician/everypolitician-data/master/countries.json" | |
%{body: data} = url |> HTTPoison.get! | |
{:ok, json} = JSON.decode(data) | |
persist_countries(json) | |
end | |
defp persist_countries([country | countries]) do | |
IO.puts "creating country #{country["name"]}" | |
Governments.create_country( | |
%{ | |
"name" => country["name"], | |
"code" => country["code"], | |
"slug" => String.downcase(country["slug"]), | |
} | |
) | |
persist_countries(countries) | |
end | |
defp persist_countries([]), do: nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment