Skip to content

Instantly share code, notes, and snippets.

@hughlilly
Created April 15, 2020 10:50
Show Gist options
  • Save hughlilly/87a00a2572e1b63fcbcb74ef0f254ff3 to your computer and use it in GitHub Desktop.
Save hughlilly/87a00a2572e1b63fcbcb74ef0f254ff3 to your computer and use it in GitHub Desktop.
Get Flickr content and dump to JSON
import yaml
import requests
import json
import flickrapi
import webbrowser
from pprint import pprint as pp
config_file = 'auth.yaml'
with open(config_file, 'r') as config_file:
config = yaml.safe_load(config_file)
api_key = config['flickr']['consumer_key']
api_secret = config['flickr']['consumer_secret']
flickr = flickrapi.FlickrAPI(api_key, api_secret, format='parsed-json')
# Authentication. Only do this if we don't have a valid token already
if not flickr.token_valid(perms='read'):
# Get a request token
flickr.get_request_token(oauth_callback='oob')
# 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='read')
webbrowser.open_new_tab(authorize_url)
print (authorize_url)
# Get the verifier code from the user. Do this however you
# want, as long as the user gives the application the code.
verifier = str(input('Verifier code: '))
# Trade the request token for an access token
flickr.get_access_token(verifier)
# Get all data
# data = 'description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o'
# Just get desc, _o URL, and tags
data = 'description, tags, url_o'
# Just desc
# data = 'description'
resp = flickr.photos.search(user_id='182826961@N04',per_page=500,page=5,privacy_filter=1,extras=data)
# pp (resp)
# resp = flickr.photos.getInfo(photo_id='48753450128')
with open ('output.json','w') as outfile:
json.dump(resp, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment