This repository has been archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.rb
100 lines (86 loc) · 2.59 KB
/
get.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env ruby -wKU
require 'flickraw-cached'
require "#{File.dirname(__FILE__)}/helpers"
SEPARATOR = "\nNikon
------------------------------------------------------------
Canon\n"
FlickRaw.api_key = "88d95a26510271b373cadcdd9e18ab14"
FlickRaw.shared_secret = "8e86dfa5ebf15ef8"
dump = File.open("cameras.txt", "a+")
options = {
:tags => nil,
:page => 1,
:per_page => 10,
:privacy_filter => 1,
:media => "photos",
:accuracy => 3,
#:machine_tags => "camera:",
:content_type => 1
}
pages = [5,4,3,2,1]
begin
options[:tags] = "nikon"
pages.each do |page|
options[:page] = page
nikon = flickr.photos.search( options )
good_nikon = File.open("good_nikon.csv", "a+")
nikon.each do |p|
begin
exif = flickr.photos.getExif(:photo_id => p.id)
dump.write("#{p.id} taken with a #{exif.camera}\n")
if exif.camera.include?("Nikon")
url = FlickRaw.url_b(flickr.photos.getInfo(:photo_id => p.id))
puts "(#{p.id}) #{p.title}: #{url}"
if exif.camera.include?("Nikon") && exif.camera.index(/D(\d+)(S?)/) != nil
good_nikon.write "#{p.id},\"Nikon\",\"#{url}\"\n"
end
end
rescue FlickRaw::FailedResponse
rescue Timeout::Error, Errno::ETIMEDOUT
rescue Interrupt
exit(0)
end
end
nikon = nil
end
puts SEPARATOR
options[:tags] = "canon"
pages.each do |page|
options[:page] = page
canon = flickr.photos.search( options )
good_canon = File.open("good_canon.csv", "a+")
canon.each do |p|
begin
exif = flickr.photos.getExif(:photo_id => p.id)
dump.write("#{p.id} taken with a #{exif.camera}\n")
if exif.camera.include?("Canon")
url = FlickRaw.url_b(flickr.photos.getInfo(:photo_id => p.id))
puts "(#{p.id}) #{p.title}: #{url}"
if exif.camera.include?("Canon") && Helpers.include?(exif.camera, ["EOS", "Rebel", "Mark"])
good_canon.write "#{p.id},\"Canon\",\"#{url}\"\n"
end
end
rescue FlickRaw::FailedResponse
rescue Timeout::Error, Errno::ETIMEDOUT
rescue Interrupt
exit(0)
end
end
end
dump.close
rescue FlickRaw::FailedResponse => e
puts "Error #{e.code} - #{e.message} - \n"
for line in e.backtrace
puts "\t#{line}"
end
puts "\n#{e}"
rescue TypeError => e
puts "#{e.class}: #{e.message} on line #{e.backtrace[0]}"
rescue Interrupt
exit(0)
rescue Exception => e
puts "#{e.class} - #{e.message} - \n"
for line in e.backtrace
puts "\t#{line}"
end
end