end
# Check then mutate all AviaNZ .data labels (Species column)
# using JSON3
# a=glob("*.WAV.data")
# check_and_change_labels!(a, "somethning", "something")
function check_change_avianz_species!(list::Vector{String}, wrong::String, right::String)
function mutate_avianz_dict!(dct, wrong::String, right::String)
didmutate = false
data = copy(dct)
for (index1, item1) in enumerate(data[2:end])
for (index2, item2) in enumerate(item1[5])
if item2[:species] == wrong
data[index1+1][5][index2][:species] = right
didmutate = true
end
end
end
return (didmutate, data)
end
function read_avianz_data(f)
json_string = read(f, String)
x = JSON3.read(json_string)
return x
end
function write_new_file!(f, payload)
cp(f, "$f.backup")
open(f, "w") do io
JSON3.write(io, payload)
end
end
for file in list
x = read_avianz_data(file)
if length(x) >= 2 #ignores empty .data files
didmutate, payload = mutate_avianz_dict!(x, wrong, right)
if didmutate == true
try
write_new_file!(file, payload)
catch
@warn "Could not write file or backup: $file"
end
end
end
end
end