{"id":890,"date":"2009-10-27T22:21:57","date_gmt":"2009-10-28T05:21:57","guid":{"rendered":"http:\/\/juixe.com\/techknow\/?p=890"},"modified":"2009-10-27T22:21:57","modified_gmt":"2009-10-28T05:21:57","slug":"download-twitter-profile-images-using-ruby","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2009\/10\/27\/download-twitter-profile-images-using-ruby\/","title":{"rendered":"Download Twitter Profile Images Using Ruby"},"content":{"rendered":"<p>Recently, I gave myself the small task of going through all my Twitter retries and downloading each profile image from each Twitter user that replied to me.  To access my Twitter replies I used the <a href=\"http:\/\/juixe.com\/techknow\/index.php\/2009\/01\/12\/twitter-ruby-gem\/\">Twitter Ruby Gem<\/a>.  I am using Twitter gem version 0.4.1.<\/p>\n<p>The script is small and pretty concise that it can speak for itself.  I use my Twitter credential to log on and query for the 40 most recent replies.  For each reply download the user&#8217;s profile image.<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nrequire 'rubygems'\r\n\r\ngem 'twitter', '=0.4.1'\r\n\r\nrequire 'twitter'\r\nrequire 'open-uri'\r\nrequire 'find'\r\n\r\ntwitter = Twitter::Base.new(username, password)\r\nreplies = twitter.replies(:count =&gt; 40)\r\n\r\nreplies.each do |status|\r\n  user = status.user\r\n  image_url = user.profile_image_url\r\n  image_name = image_url.match(\/(&#x5B;\\w_]+).(\\w\\w\\w)$\/)\r\n  file_path = &quot;profile\/#{image_name&#x5B;1]}.#{image_name&#x5B;2]}&quot;\r\n\r\n  # Did I already download this image?\r\n  unless File.exists?(file_path)\r\n    File.open(file_path, 'w') do |output|\r\n      # Download image\r\n      open(image_url) do |input|\r\n        output &lt;&lt; input.read\r\n      end\r\n    end\r\n  end  \r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I gave myself the small task of going through all my Twitter retries and downloading each profile image from each Twitter user that replied to me. To access my Twitter replies I used the Twitter Ruby Gem. I am using Twitter gem version 0.4.1. The script is small and pretty concise that it can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[22],"tags":[59,58,806,50,28],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-em","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/890"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=890"}],"version-history":[{"count":2,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":892,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/890\/revisions\/892"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}