Skip to content

Instantly share code, notes, and snippets.

@tommyp
Created May 13, 2018 13:59
Show Gist options
  • Save tommyp/bfd977d8160f2606dd2d5988c7419313 to your computer and use it in GitHub Desktop.
Save tommyp/bfd977d8160f2606dd2d5988c7419313 to your computer and use it in GitHub Desktop.
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