adds rake task to assign demographic info to users

This commit is contained in:
kikito
2016-04-12 17:06:50 +02:00
parent 2c51115d6d
commit 0ae97eada8

View File

@@ -40,5 +40,23 @@ namespace :users do
end
end
desc "Associates demographic information to users"
task assign_demographic: :environment do
User.residence_verified.where(genre: nil).find_each do |u|
begin
response = CensusApi.new.call(u.document_type, u.document_number)
if response.valid?
u.genre = response.genre == 'Varón' ? 'male' : 'female'
u.date_of_birth = response.date_of_birth.to_datetime
u.save
print "."
else
print "X"
end
rescue
puts "Could not assign genre/dob for user: #{u.id}"
end
end
end
end