将Flickr照片上载到Strongspace
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Flickr照片上载到Strongspace相关的知识,希望对你有一定的参考价值。
equire '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
以上是关于将Flickr照片上载到Strongspace的主要内容,如果未能解决你的问题,请参考以下文章