def handle(self, *args, **options):
     if len(args) != 0:
         raise CommandError("Command doesn't accept any arguments")
     
     client = Flickr()
     
     photos = Photo.objects.filter(
         taken_at__isnull = True
     ).exclude(flickr_id = '')
     
     for photo in photos:
         try:
             taken_at = parser.parse(
                 client.photos_getInfo(
                     photo_id = photo.flickr_id,
                     secret = photo.flickr_secret
                 )['photo']['dates']['taken']
             )
         except KeyError:
             print "No date found for id: %s" % photo.flickr_id
         else:
             photo.taken_at = taken_at
             photo.save()
             print "Saved date for %s" % photo.flickr_id
         time.sleep(2)
def import_photo_sets_for_photos_belonging_to_user(user):
    f = Flickr()
    for photo in user.photos.all():
        if not photo.flickr_id:
            continue
        result = f.photos_getAllContexts(photo_id = photo.flickr_id)
        if 'set' not in result:
            continue
        sets = result['set']
        for set in sets:
            s, created = FlickrSet.objects.get_or_create(
                flickr_id = set['id'],
                defaults = {
                    'user': user,
                    'title': set['title'],
                }
            )
            s.photos.add(photo)
            print u"Added %s to set %s" % (photo, set)
        time.sleep(5)