-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickr_download.rb
70 lines (49 loc) · 1.63 KB
/
flickr_download.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
#
# Download photos belonging to some group
# jssmk @ Helsinki Hacklab
#
# Start with editing your locals.rb file, use locals_default.rb as a template
require_relative 'locals'
local_pic_list = Dir[PIC_path+"**{.JPG,.jpg}"]
require 'flickraw'
#require 'exifr'
require 'logger'
require 'open-uri'
# Logfile
$mylog = Logger.new(LOG_path+'flickr_download_log.txt', 10, 1024000)
$mylog.info("Start ---->")
# If there is no internet connection, exit
begin
# We trust google is up
open("http://www.google.com")
rescue
$mylog.info("---> no internet connection")
exit
end
FlickRaw.api_key = MY_api_key
FlickRaw.shared_secret = MY_shared_secret
# List all photos in the group
$group_pic_list = flickr.groups.pools.getPhotos api_key: FlickRaw.api_key, group_id: MY_group_id
$mylog.info("Number of pics to download "+$group_pic_list.length.to_s)
for pic in $group_pic_list
if local_pic_list.include?(PIC_path+pic.id+'.jpg')
# This pic is already downloaded
else
info = flickr.photos.getInfo api_key: MY_api_key, photo_id: pic.id
$mylog.info("getting info for pic: " + pic.id)
print("Downloading pic: " + info.title + "\n")
begin
sizes = flickr.photos.getSizes api_key: MY_api_key, photo_id: pic.id
rescue FlickRaw::FailedResponse => e
$mylog.error("getting sizes for pic " + pic.id + " failed")
exit
end
org_size = sizes.size.select {|s| s.label == 'Original'}[0]
# Start downloading
open(PIC_path + pic.id + '.jpg', 'wb') do |file|
file << open(org_size.source).read
end
$mylog.info("downloaded pic: "+pic.id)
end
end
$mylog.info("----> End")