Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

find photos that are interesting /and/ relevant

  • Loading branch information...
commit 8cdca9eec4021c6edcb2c0e76f1c10e926038cce 1 parent 1cd0fae
Andrew Carpenter authored
Showing with 29 additions and 9 deletions.
  1. +29 −9 lib/flickr.rb
View
38 lib/flickr.rb
@@ -4,7 +4,6 @@
class Flickr
class Photo
attr_accessor :id, :title, :owner, :farm, :server, :secret
-
def initialize(attributes)
@id = attributes["id"]
@title = attributes["title"]
@@ -13,7 +12,11 @@ def initialize(attributes)
@server = attributes["server"]
@secret = attributes["secret"]
end
-
+
+ def hash
+ @id.hash
+ end
+
def creator
@creator ||= Person.new(owner)
end
@@ -25,6 +28,21 @@ def url(size)
def self.find_by_id(id)
Photo.new(flickr.photos.getInfo(:photo_id => id))
end
+
+ def of_appropriate_size?
+ large_size_info = raw_sizes.find{|s| s.label == 'Large'}
+ if large_size_info
+ large_size_info['width'].to_i >= 850
+ else
+ false
+ end
+ end
+
+ private
+
+ def raw_sizes
+ @raw_sizes ||= flickr.photos.getSizes(:photo_id => id)
+ end
end
class Person
@@ -44,13 +62,15 @@ def initialize
end
def search(q)
- flickr.photos.search(
+ conditions = {
:text => q,
:license => '1,2,4,5,7,8',
- :per_page => 25,
- :sort => 'interestingness-desc'
- ).map do |attributes|
- Photo.new(attributes)
- end
+ :per_page => 500
+ }
+ relevant = flickr.photos.search(conditions.merge :sort => 'relevance').map{|attr| Photo.new(attr)}
+ interesting = flickr.photos.search(conditions.merge :sort => 'interestingness-desc').map{|attr| Photo.new(attr)}
+
+ relevant_and_interesting_ids = relevant.map(&:id) & interesting.map(&:id)
+ (relevant.select{|photo| relevant_and_interesting_ids.include?(photo.id)} + relevant).uniq
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.