My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require 'rubygems'
require 'open-uri'
require 'net/http'
require 'uri'
require 'rexml/document'

namespace "photos" do


desc "Find licenses on Flickr"
task :get_licenses => [:environment] do

key = FLICKR_KEY
secret = FLICKR_SECRET
flickr_url = "http://api.flickr.com/services/rest/"
method = "flickr.photos.licenses.getInfo"

url = flickr_url + "?api_key=" + key + "&method=" + method
puts url

response = open(url)
doc = REXML::Document.new(response.read)
doc.elements.each('//rsp/licenses/license') do |license|
if license.attributes["url"] != ""
@licence = Licence.find_by_url(license.attributes["url"])

if @licence
puts "License already known about."
else
@licence = Licence.new(:url => license.attributes["url"], :name => license.attributes["name"])
if @licence.save
puts "Saved new license"
else
puts "Error saving license"
end
end
end
end

end

desc "Find photos on Flickr"
task :find => [:environment] do
key = "86c115028094a06ed5cd19cfe72e8f8b"
secret = "d371b9edd648fa19"
content_type = "1" # Photos only
machine_tag_key = "openplaques:id"

flickr_url = "http://api.flickr.com/services/rest/"
method = "flickr.photos.search"
license = "1,2,3,4,5,6,7" # All the CC licencses that allow commercial re-use


url = flickr_url + "?api_key=" + key + "&method=" + method + "&license=" + license + "&content_type=" + content_type + "&machine_tags=" + machine_tag_key + "=&extras=date_taken,owner_name,license,geo,machine_tags"

new_photos_count = 0
response = open(url)
doc = REXML::Document.new(response.read)
doc.elements.each('//rsp/photos/photo') do |photo|
print "."
$stdout.flush

@photo = nil

file_url = "http://farm" + photo.attributes["farm"] + ".static.flickr.com/" + photo.attributes["server"] + "/" + photo.attributes["id"] + "_" + photo.attributes["secret"] + "_m.jpg"
photo_url = "http://www.flickr.com/photos/" + photo.attributes["owner"] + "/" + photo.attributes["id"] + "/"

@photo = Photo.find_by_url(photo_url)


if @photo
else
plaque_id = photo.attributes["machine_tags"][/openplaques\:id\=(\d+)/, 1]

@plaque = Plaque.find(:first, :conditions => {:id => plaque_id})
if @plaque
@photo = Photo.new
@photo.plaque = @plaque
@photo.file_url = file_url
@photo.url = photo_url
@photo.taken_at = photo.attributes["datetaken"]
@photo.photographer_url = photo_url = "http://www.flickr.com/photos/" + photo.attributes["owner"] + "/"
@photo.photographer = photo.attributes["ownername"]
if photo.attributes["license"] == "4"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by/2.0/")
elsif photo.attributes["license"] == "6"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by-nd/2.0/")
elsif photo.attributes["license"] == "3"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by-nc-nd/2.0/")
elsif photo.attributes["license"] == "2"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by-nc/2.0/")
elsif photo.attributes["license"] == "1"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by-nc-sa/2.0/")
elsif photo.attributes["license"] == "5"
@photo.licence = Licence.find_by_url("http://creativecommons.org/licenses/by-sa/2.0/")
elsif photo.attributes["license"] == "7"
@photo.licence = Licence.find_by_url("http://www.flickr.com/commons/usage/")
else
puts "Couldn't find license"
end
if @photo.save
new_photos_count += 1
#puts "New photo found and saved"
else
puts "Error saving photo" + @photo.errors.each_full{|msg| puts msg }
end

if photo.attributes["latitude"] != "0" && photo.attributes["longitude"] != "0" && !@plaque.geolocated?
puts "New geolocation found"
@plaque.latitude = photo.attributes["latitude"]
@plaque.longitude = photo.attributes["longitude"]
@plaque.accuracy = 'flickr'
if @plaque.save
puts "New geolocation added to photo"
else
puts "Error adding geolocation to photo" + plaque.errors.full_messages.to_s #methods.join(" ")
end
end



else
#puts "Photo's machine tag doesn't match a plaque."
end
end
end

puts "\n" + new_photos_count.to_s + " new photos found and saved."

end
end

Change log

r380 by fr4nkieroberto on Feb 6, 2010   Diff
Fixes  Issue 165 
Go to: 
Sign in to write a code review

Older revisions

r234 by simon.harriyott on Jun 18, 2009   Diff
 Issue 108 
Changed plaque.geocoded to
plaque.geo.located
r222 by jez.nicholson on Jun 10, 2009   Diff
 Issue 71 :       If a geolocation is
obtained from Flickr set
plaque.accuracy to 'flickr'
r3 by fr4nkieroberto on May 9, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 4900 bytes, 131 lines
Powered by Google Project Hosting