Skip to content

Instantly share code, notes, and snippets.

@edsu
Created July 8, 2009 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsu/142889 to your computer and use it in GitHub Desktop.
Save edsu/142889 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Print out a list of links between Flickr and Chronicling America. These are newspaper pages that have had images extracted from them, that have been uploaded to Flickr by Dave Woodward.
"""
import json
import urllib
# http://www.flickr.com/services/api/keys/
key = 'REAL_FLICKR_KEY_HERE'
def newspaper_photo_ids():
u = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=%s&photoset_id=72157619452486566&format=json&nojsoncallback=1' % key
photos = json.loads(urllib.urlopen(u).read())
return photos['photoset']['photo']
def flickr_url(photo_id):
return 'http://www.flickr.com/photos/library_of_congress/%s' % photo_id
def chronam_url(photo_id):
u = 'http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=%s&photo_id=%s&format=json&nojsoncallback=1' % (key, photo_id)
j = json.loads(urllib.urlopen(u).read())
for tag in j['photo']['tags']['tag']:
if 'chroniclingamerica.loc.gov' in tag['raw']:
return tag['raw'].replace('dc:identifier=', '')
return None
def flickr_chronam_links():
for photo in newspaper_photo_ids():
yield flickr_url(photo['id']), chronam_url(photo['id'])
for link in flickr_chronam_links():
print link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment