Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Created August 10, 2022 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeledet/1339b65bba5fdb9e794088efa229986a to your computer and use it in GitHub Desktop.
Save lukeledet/1339b65bba5fdb9e794088efa229986a to your computer and use it in GitHub Desktop.
Turn a directory of token files into a tab separated list
Mix.install([:jason])
attribute_order = ["background", "body", "tattoos", "costume", "mane", "face", "eyes", "snout", "hat", "flinger"]
File.cd("tokens")
File.ls!()
|> Enum.filter(&(&1 =~ ".json"))
|> Enum.sort_by(&Float.parse/1)
|> Enum.map(fn f ->
f
|> File.read!()
|> Jason.decode!()
|> Map.get("attributes")
|> Enum.map(&{Map.get(&1, "trait_type"), Map.get(&1, "value")})
|> Enum.into(%{})
|> then(fn a ->
id = String.replace(f, ".json", "")
IO.write("#{id}")
Enum.each(attribute_order, &(IO.write("\t#{Map.get(a, &1)}")))
end)
IO.write("\n")
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment