lib/flickr_airlift.rb in flickr_airlift-0.2.1 vs lib/flickr_airlift.rb in flickr_airlift-0.3.0
- old
+ new
@@ -1,9 +1,11 @@
+require "flickr_airlift/version"
require 'flickraw'
require 'net/http'
require 'cgi'
require 'launchy'
+require 'yaml'
module FlickrAirlift
UPLOADABLE_FORMATS = [".jpg", ".jpeg", ".gif", ".png", ".mov", ".avi"]
@@ -28,16 +30,19 @@
Dir.mkdir(scraped_user) unless File.directory?(scraped_user)
(1..page_count.to_i).each do |page_number|
puts "* PAGE #{page_number} of #{page_count}"
flickr.photos.search(:user_id => user_id, :page => page_number).each_with_index do |photo, i|
- photo_id = photo.id
- info = flickr.photos.getInfo(:photo_id => photo_id)
- download_url = flickr.photos.getSizes(:photo_id => photo_id).find{|size| size.label == "Original" || size.label == "Large" || size.label == "Medium"}.source
+ photo_id = photo.id
+ info = flickr.photos.getInfo(:photo_id => photo_id)
+ photo_size_objects = flickr.photos.getSizes(:photo_id => photo_id)
+
+ download_url = flickr.photos.getSizes(:photo_id => photo_id).find{|size| size.label == "Original"}.source
+
puts "** Downloading #{i+1}: #{photo.title} from #{download_url}"
- File.open(File.join(scraped_user, "#{photo_id}.jpg"), 'w') do |file|
+ File.open(File.join(scraped_user, "#{info.title}#{File.extname(download_url)}"), 'wb') do |file|
file.puts Net::HTTP.get_response(URI.parse(download_url)).body
end
end
end
@@ -66,16 +71,16 @@
Launchy.open(edit_url)
end
def self.establish_session
- auth_file = File.expand_path("~/.flick_airliftrc")
+ auth_file = File.join(Dir.home(), ".flick_airliftrc")
FlickRaw.api_key = "3b2360cc04947af8cf59f51c47a6a8e4"
FlickRaw.shared_secret = "405549bcec106815"
if File.exists?(auth_file)
- puts "authenticating thought #{auth_file}"
+ puts "authenticating through #{auth_file}...if this fails - delete this file"
data = YAML.load_file(auth_file)
auth = flickr.auth.checkToken :auth_token => data["api_token"]
else
frob = flickr.auth.getFrob
auth_url = FlickRaw.auth_url :frob => frob, :perms => "write"
@@ -92,11 +97,9 @@
# Authentication
auth = flickr.auth.getToken :frob => frob
login = flickr.test.login
puts auth.token
-
- require 'yaml'
data = {}
data["api_token"] = auth.token
File.open(auth_file, "w"){|f| YAML.dump(data, f) }
end
end
\ No newline at end of file