Commits

Ethan Sherbondy committed 9d2cd2a

Verifies that the images are the correct dimensions before attempting to download.

Comments (0)

Files changed (1)

 
 def getFlickrImages():
     """ Returns the urls for 20 flickr images at a time.
-        We do 20 instead of 10 as a safenet, 
+        We do 30 instead of 10 as a safety net, 
         because some images don't have
-        z-size versions."""
+        z-size versions, and some are too small in
+        one dimension."""
     
     flickr_key = "9c09d89ec4352d9efebd8fc4fa679c48"
     photo_urls = []
     params = urllib.urlencode({'method': "flickr.interestingness.getList", 
                                'api_key': flickr_key,
                                'date': flickr_date,
-                               'per_page': '20',
-                               'extras': 'url_l',
+                               'per_page': '30',
+                               'extras': 'url_l,o_dims',
                                'format': 'json'})
 
     url = "http://api.flickr.com/services/rest/?"+params
         data = json.loads(response.read()[14:-1])
         for photo in data["photos"]["photo"]:
             try:
+                # verify that the url actually exists
                 if urlparse(photo["url_l"]).scheme:
-                    photo_urls.append(photo["url_l"])
+                    # make sure the image is at least 500x500
+                    # (our intended output size)
+                    if photo["height_l"] >= 500 and photo["width_l"] >= 500:
+                        photo_urls.append(photo["url_l"])
             except Exception, e:
                 pass
     except urllib2.URLError, e: