After taking photos and adding them to my Flickr page, I use this script to pull location information, title, and URL from my photos. From there, I create a .csv of the photo information. Then, using ArcGIS Online, I create a shapefile of the picture locations. Once added to the map, I pull the photos' locations using the URL atribute to present the photograph in the intereactive pop-up window.
In [1]:
#import the flickrapi library
import flickrapi
In [2]:
#sign up for Flickr access: https://www.flickr.com/services/apps/create/apply/?
api_key = api_key #enter your API key here. DO NOT SAVE KEY IF STORE PUBLICLY
api_secret = api_secret #enter your API secret here. DO NOT SAVE IF STORED PUBLICLY
user_id = user_idea
In [3]:
#Instantiate Flickr API using your key
flickr = flickrapi.FlickrAPI(api_key, api_secret,format='etree')
#Build a method name for Albums
sets = flickr.photosets.getList(user_id=user_id)
In [ ]:
#Determine the possible sets available for use
for set in sets.getchildren()[0]:
title = set.getchildren()[0].text
print (("id: %s setname: %s photos: %s") %(set.get('id'), title, set.get('photos')))
In [17]:
#set the set_ID you want from the output above using the title as a guide
set_id = set_id
#Use .walk_set to go through the photos in a set, pull information into a dataframe, and combine each dataframe into a sgin
#create empty list
listing = []
for photo in flickr.walk_set(set_id,extras='geo,url_o'):
#pull items for DataFrame
id_ = (photo.get('id'))
title = (photo.get('title'))
latitude = (photo.get('latitude'))
longitude = (photo.get('longitude'))
url_ = (photo.get('url_o'))
#create DataFrame for each photo
frame = pd.DataFrame({'Neighborhood':title,'latitude':latitude,'longitude':longitude,'URL':url_},index=[id_])
#Append list with new DataFrame
listing.append(frame)
#Combine each DataFrame into a single frame
centroid_photos = pd.concat(listing)
In [6]:
#save as .csv
centroid_photos.to_csv('flickr_updated.csv')