Skip to content

Instantly share code, notes, and snippets.

Last active September 17, 2017 16:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import flickrapi
import urllib
import json
import random
import filecmp
import shutil
import os.path
from pprint import pprint
api_key = u'your api key'
api_secret = u'your api secret'
access_token = u'xxxxxxxxxxxxxxxxxx-xxxxxxxxxxxx' # these two get filled in in a bit
token_secret = u'xxxxxxxxxxxxx'
user_id = "your user id" # mine was 48889036627@N01
flickr = flickrapi.FlickrAPI(api_key, api_secret,format='parsed-json')
photos = []
print('Step 1: authenticate')
# Only do this if we don't have a valid token already
if not flickr.token_valid(perms='read'):
# Get a request token
# Open a browser at the authentication URL. Do this however
# you want, as long as the user visits that URL.
authorize_url = flickr.auth_url(perms=u'read')
# Get the verifier code from the user. Do this however you
# want, as long as the user gives the application the code.
verifier = unicode(raw_input('Verifier code: '))
# Trade the request token for an access token
print('Step 2: use Flickr')
# assumes you have a file from the output of flickrmirrorer, e.g.
# find . | grep "\.metadata" > list_of_photos.txt
with open("list_of_photos.txt") as f:
for line in f:
photo_id = line.rstrip()
photo_id = photo_id.replace("./data/photostream/","")
photo_id = photo_id.replace(".metadata","")
photo_id = photo_id.replace(".jpg","")
photo_id = photo_id.replace(".png","")
resp =,photo_id=photo_id,authenticated=True)
filen = "metadata/"+photo_id+".json"
file = open(filen,"w")
file.write(json.dumps(resp, indent=4))
e = sys.exc_info()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment