Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Johan S�rensen http://johansorensen.com

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Upload your Flickr photos to Strongspace

require 'net/http'
require 'rubygems'
require_gem 'flickr'
require_gem 'net-sftp'

flickr_username = "[email protected]"
flickr_pass = 'x'
strongie_pass = 'x'
strongie_username = 'johan'
strongie_upload_dir = "flickr_test"

flickr = Flickr.new 
flickr.login(flickr_username, flickr_pass)
user = flickr.users(flickr_username)

Net::SFTP.start("#{strongie_username}.strongspace.com", strongie_username, strongie_pass) do |sftp|
  Net::HTTP.start('static.flickr.com') do |http|
    user.photos.each do |photo|
      src_url = photo.source('Large').sub("http://static.flickr.com", '')    
      puts "Fetching \"#{photo.title}\"..."
      res = http.get(src_url)
      filename = File.basename(src_url)
      sftp.open_handle("/home/#{strongie_username}/#{strongie_upload_dir}/#{filename}", 'w') do |handle|
        result = sftp.write(handle, res.body)
        puts "Wrote #{filename} with result code: #{result.code}..."
      end    
    end
  end
end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed