Created
August 10, 2022 16:57
-
-
Save lukeledet/1339b65bba5fdb9e794088efa229986a to your computer and use it in GitHub Desktop.
Turn a directory of token files into a tab separated list
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
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