]> git.openstreetmap.org Git - rails.git/commitdiff
Add stupid script to bulk check the gravatar status
authorSimon Poole <simon@poole.ch>
Fri, 26 Feb 2016 10:41:28 +0000 (11:41 +0100)
committerSimon Poole <simon@poole.ch>
Tue, 16 Aug 2016 20:09:11 +0000 (22:09 +0200)
script/gravatar [new file with mode: 0755]

diff --git a/script/gravatar b/script/gravatar
new file mode 100755 (executable)
index 0000000..e14e7ea
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# require File.dirname(__FILE__) + "/../config/environment"
+
+start = 0
+User.where("image_use_gravatar AND id >=" + start.to_s).order("id").find_each do |user|
+  p "checked up to id " + user.id.to_s if user.id % 1000 == 0 # just give a rough indication where we are for restarting
+  next if user.image.present?
+  hash = Digest::MD5.hexdigest(user.email.downcase)
+  url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
+  response = OSM.http_client.get(URI.parse(url))
+  user.image_use_gravatar = response.success?
+  user.save
+  sleep(1)
+end
+
+exit 0