Created
December 5, 2013 18:02
-
-
Save andrewljohnson/7810218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_point_photos(request, lat, lon, name): | |
'''takes a lat lon pair via an ajax request, and returns a list of photos''' | |
#create a Flickr API object | |
f = flickrapi.FlickrAPI(api_key) | |
#resolve a (lat,long) to a "Flickr Place" which can be used to search for photos. | |
place = f.places_findByLatLon(api_key = api_key, lat=lat, lon = lon) | |
#get the id of the Flickr Place returned | |
place_id = place.find('places').findall('place')[0].attrib['place_id'] | |
#returns an XML response that contains data to construct photo URLs | |
flickr_search = f.photos_search(api_key = api_key, place_id = place_id, content_type = '1', tags = 'nature, landscape, hiking, outdoors, | |
trip, sky, sunset, sunrise, ' + name) | |
photos = [] | |
photos_per_page = 12 | |
for i in range(0,photos_per_page): | |
photo_xml = None | |
try: | |
photo_xml = flickr_search.find('photos').findall('photo')[i] | |
except: | |
break | |
photo = {} | |
photo['url'] = get_url_from_photo(photo_xml) | |
photo['home_url'] = get_home_url_from_photo(photo_xml) | |
photos.append(photo) | |
response_dict = {'success':True, 'photos':photos} | |
return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment