Skip to content

Instantly share code, notes, and snippets.

@rajraj
Created March 17, 2011 22:45
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 rajraj/875299 to your computer and use it in GitHub Desktop.
Save rajraj/875299 to your computer and use it in GitHub Desktop.
Rapleaf Name to Gender API
namespace :ycpages do
desc "Update person gender using RapLeaf's name to gender API."
task :update_gender => :environment do
Person.all.each do |person|
unless person.gender.present?
url = "http://api.rapleaf.com/v4/util/name_to_gender/#{person.name.split.first}"
response = Net::HTTP.get_response(URI.parse(url))
result = JSON.parse(response.body)
if ((result["status"] == "OK") && (result["answer"]["likelihood"].to_f > 0.9))
person.update_attribute(:gender, result["answer"]["gender"])
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment