-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickr_lube.rb
executable file
·72 lines (69 loc) · 2.44 KB
/
flickr_lube.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/ruby
#stick yours in here.
username = 'YOUR_FLICKR_USERNAME'
begin
require 'rubygems'
rescue LoadError
puts "Flickr Lube needs RubyGems installed on your server to continue, and we can't find it."
puts 'See http://rubygems.org for installation instructions'
exit
end
begin
gemnames = ['fleakr']
gemnames.each do |gname|
require gname
end
rescue LoadError
puts "Flickr Lube uses Fleakr to get things greased up. Try 'sudo gem install fleakr' and then put some nice music on."
puts "If your system doesn't let you sudo, http://rubygems.org/read/chapter/3#page83 has instructions on getting around that. This will be worth it."
puts "Do you want this script to try to install the gems for you? (y/n):"
if gets.chomp.downcase == 'y'
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
gemnames.push 'builder'
gemnames.each do |gname|
installer.install(gname)
end
end
puts "If everything installed fine, you should be able to run the script now"
exit
end
#if this stops working, no prob. Go here:
#http://www.flickr.com/services/api/keys/apply/
#get a new key, put it right here
Fleakr.api_key = 'ff49d13c700dc4942fd7bdfe6f24ab61'
def process_photos(photos,dir,title,description,size,photo_ids_to_exclude)
puts "processing " + title
processed_ids = []
images = {}
info = {}
info['directory'] = {'title' => title, 'description' => description}
FileUtils.mkdir(dir) unless File.exist?(dir)
template = "%0#{photos.length.to_s.length}d_"
photos.each_with_index do |photo, index|
next if photo_ids_to_exclude.include?(photo.id)
puts "processing " + photo.title
image = photo.send(size)
unless image.nil?
prefix = sprintf(template,(index+1))
image.save_to(dir,prefix)
images[prefix+image.filename] = {'title' => photo.title, 'desc' => photo.description.gsub("\n",'<br/>')}
processed_ids.push(photo.id)
end
end
info['images'] = images
File.open(dir+'/info.yml', 'w') do | file|
YAML.dump(info, file)
end
processed_ids
end
# Find a user
user = Fleakr.user(username)
photos_in_sets = []
# save each set to a folder
user.sets.each do | set|
photos_in_sets += process_photos(set.photos,"./data/"+set.title,set.title,set.description,:large,photos_in_sets)
end
puts "processing photos not in sets"
# save each photo to this folder
process_photos(user.photos,"./data/From Flickr","Main Photos","pulled out of flickr",:large,photos_in_sets)