Skip to content

Instantly share code, notes, and snippets.

@blech
Created January 10, 2010 17:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blech/273614 to your computer and use it in GitHub Desktop.
Save blech/273614 to your computer and use it in GitHub Desktop.
Find Flickr galleries by contacts
#!/usr/bin/python
import feedparser
import flickrapi
import simplejson
import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
keys = {
'flickr_key': " ", # put your key and secret here. I'm not giving you mine.
'flickr_sec': " ",
}
flickr = flickrapi.FlickrAPI(keys['flickr_key'], keys['flickr_sec'], )
flickr.cache = flickrapi.SimpleCache(timeout=300, max_entries=200)
stats = {'users': 0, 'notusers': 0, 'galleries': 0,}
json = flickr.contacts_getList(
per_page=1000,
format='json',
nojsoncallback="1",
)
contacts = simplejson.loads(json)
print "Looking for galleries from %s contacts" % len(contacts['contacts']['contact'])
for contact in contacts['contacts']['contact']:
# print "%s - %s" % (contact['nsid'], contact['username'])
feed_url = "http://www.flickr.com/services/feeds/galleries_user.gne?user_id=%s&format=atom" % contact['nsid']
gallery = feedparser.parse(feed_url)
if len(gallery['entries']):
stats['users'] += 1
print "Galleries by %s (%s):" % (contact['username'], len(gallery['entries']))
for entry in gallery['entries']:
print "\t%s - %s (%s)" % (entry['title'], entry['link'], entry['published'])
# print "\n%s\n\n" % entry['subtitle']
stats['galleries'] += 1
else:
stats['notusers'] += 1
print "\n%s galleries from %s contacts. (%s contacts have no galleries.)" % (stats['galleries'], stats['users'], stats['nonusers']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment