Skip to content

Instantly share code, notes, and snippets.

@barnes7td
Created March 17, 2016 20:24
Show Gist options
  • Save barnes7td/e2d05d28fd612d41e4a4 to your computer and use it in GitHub Desktop.
Save barnes7td/e2d05d28fd612d41e4a4 to your computer and use it in GitHub Desktop.
people_json_filter_bad_data.rb
require 'json'
require 'pp'
file_path = "./current_dossis.json"
dossis = JSON.parse(File.read(file_path))
named_dossis = dossis.reject { |d| d.fetch("name") == nil }
named_dossis = named_dossis.reject { |d| d.fetch("name") == "" }
named_dossis = named_dossis.reject { |d| d.fetch("name").downcase == "nil" }
named_dossis = named_dossis.reject { |d| d.fetch("name").to_s.include? "http" }
i = 0
results = []
while named_dossis.size > 574
p named_dossis.size
dossi = named_dossis[i]
common_dossis = named_dossis.select do |d|
if d && dossi
d.fetch("name") == dossi.fetch("name")
end
end
if common_dossis.count > 1
dossi.each do |key, value|
next if key == "picture" || key == "comments"
dossi[key] = common_dossis.map { |cd| cd[key] }.uniq.join("\n")
end
end
results << dossi
named_dossis.delete_if do |d|
if d && dossi
d.fetch("name") == dossi.fetch("name")
end
end
i += 1
end
p results.size
File.open("output.json","w") do |f|
f.write(results.to_json)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment