Ruby script to upload photos from my digital camera to Flickr
require "ftools"
def move_photos_from_camera_to_staging_area
puts "Moving photos from camera to staging area"
Dir["f:/DCIM/100OLYMP/*.*"].each { |filename|
File.move("#{filename}", "staging_area/#{filename.split('/').last}")
}
end
def say_upload_complete
`start "C:\\Program Files\\Winamp\\winamp.exe" "UploadPhotos.wav"`
end
require "RMagick"
include Magick
def copy_photos_to_managed_photos
puts "Copying photos to Managed Photos"
# *.* to include movies, if any [Jon Aquino 2005-04-23]
Dir["./staging_area/*.*"].each { |filename|
File.copy("#{filename}", "c:/Documents and Settings/All Users/Documents/My Pictures/Managed Photos/"+ImageList.new(filename).get_exif_by_entry("DateTime")[0][1].gsub(/:/, "_")+"jpg")
}
end
def show_explorer_window
puts "Showing explorer window"
`"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE" #{Dir.getwd}\\staging_area`
end
def photos_in_staging_area
# Dir[] is unfortunately case-sensitive [Jon Aquino 2005-04-23]
# Actually this is good as it will distinguish the original photos
# (JPG) from the resized photos (jpg) [Jon Aquino 2005-04-23]
Dir["./staging_area/*.JPG"]
end
def resize(photo_filename)
puts "Resizing #{photo_filename}"
resized_photo_filename = photo_filename.gsub(".JPG", "b.jpg")
ImageList.new(photo_filename).write(resized_photo_filename) { self.quality = 30 }
resized_photo_filename
end
require "flickr.rb"
def upload_to_flickr(filename)
puts "Uploading #{filename} to Flickr"
Upload.new.upload(filename, "", "", ["victoriabc"])
end
move_photos_from_camera_to_staging_area
say_upload_complete
copy_photos_to_managed_photos
show_explorer_window
photos_in_staging_area.each {|photo_filename|
resized_photo_filename = resize(photo_filename)
upload_to_flickr(resized_photo_filename)
File.delete(photo_filename)
File.delete(resized_photo_filename)
}
0 Comments:
Post a Comment
<< Home