Posted By

lmcdougall on 09/13/07


Tagged

http ruby


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

zemariamm
webstic


Upload your Flickr photos to Strongspace


 / Published in: Ruby
 

  1. equire 'net/http'
  2. require 'rubygems'
  3. require_gem 'flickr'
  4. require_gem 'net-sftp'
  5.  
  6. flickr_username = "[email protected]"
  7. flickr_pass = 'x'
  8. strongie_pass = 'x'
  9. strongie_username = 'johan'
  10. strongie_upload_dir = "flickr_test"
  11.  
  12. flickr = Flickr.new
  13. flickr.login(flickr_username, flickr_pass)
  14. user = flickr.users(flickr_username)
  15.  
  16. Net::SFTP.start("#{strongie_username}.strongspace.com", strongie_username, strongie_pass) do |sftp|
  17. Net::HTTP.start('static.flickr.com') do |http|
  18. user.photos.each do |photo|
  19. src_url = photo.source('Large').sub("http://static.flickr.com", '')
  20. puts "Fetching \"#{photo.title}\"..."
  21. res = http.get(src_url)
  22. filename = File.basename(src_url)
  23. sftp.open_handle("/home/#{strongie_username}/#{strongie_upload_dir}/#{filename}", 'w') do |handle|
  24. result = sftp.write(handle, res.body)
  25. puts "Wrote #{filename} with result code: #{result.code}..."
  26. end
  27. end
  28. end
  29. end

Report this snippet  

You need to login to post a comment.