-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flickr_album.rb
executable file
·44 lines (34 loc) · 1.02 KB
/
flickr_album.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
#!/usr/bin/env ruby
require 'flickraw'
require 'aws-sdk-rekognition'
require 'open-uri'
require 'json'
photoset_id = ARGV[0]
FlickRaw.api_key = ENV['FLICKR_API_KEY']
FlickRaw.shared_secret = ENV['FLICKR_SHARED_SECRET']
flickr = FlickRaw::Flickr.new
rekognition = Aws::Rekognition::Client.new(
region: 'eu-west-1',
profile: 'perso',
)
page = 1
imported = 0
loop do
puts "I: Getting photos from page #{page}"
set = flickr.photosets.getPhotos(photoset_id: photoset_id, page: page)
break if set.photo.length == 0
set.photo.each do |pic|
url = "http://farm#{pic['farm']}.staticflickr.com/#{pic['server']}/#{pic['id']}_#{pic['secret']}_b.jpg"
ref = "flickr:#{pic['farm']}:#{pic['server']}:#{pic['id']}:#{pic['secret']}"
img = open(url)
puts "Importing #{ref} (#{url}) into collection"
rekognition.index_faces({
collection_id: 'flickr',
image: { bytes: img.read },
external_image_id: ref,
})
end
page += 1
imported += set.photo.length
end
puts "imported #{imported} photos"