Changes between Version 3 and Version 4 of FlickrIntegration


Ignore:
Timestamp:
Nov 20, 2006, 10:23:14 AM (17 years ago)
Author:
Oliver Beattie
Comment:

After struggling with this on the IRC channel for an afternoon, found a problem with the sync code

Legend:

Unmodified
Added
Removed
Modified
  • FlickrIntegration

    v3 v4  
    7777#!python
    7878def sync_flickr_photos(*args, **kwargs):
    79         API_KEY = 'your_api_key_here'
    80         USER_ID = 'your_id_here'
    81        
     79        API_KEY = 'INSERT API KEY'
     80        USER_ID = 'INSERT USER ID'
     81
    8282        cur_page = 1            # Start on the first page of the stream
    8383        paginate_by = 20        # Get 20 photos at a time
    8484        dupe = False            # Set our dupe flag for the following loop
    85        
     85
    8686        client = FlickrClient(API_KEY)          # Get our flickr client running
    87        
     87
    8888        while (not dupe):
    8989                photos = client.flickr_people_getPublicPhotos(user_id=USER_ID, page=cur_page, per_page=paginate_by)
    90        
     90
    9191                for photo in photos:
    9292                        try:
    93                                 row = Photo.objects.get(flickr_id=photo("id"), flickr_secret=photo("secret"))
     93                                row = Photo.objects.get(flickr_id=photo("id"), flickr_secret=str(photo("secret")))
    9494                                # Raise exception if photo doesn't exist in our DB yet
    95                                
     95
    9696                                # If the row exists already, set the dupe flag
    9797                                dupe = True
    9898                        except ObjectDoesNotExist:
    9999                                p = Photo(
    100                                         title = photo("title"),
    101                                         flickr_id = photo("id"),
    102                                         flickr_owner = photo("owner"),
    103                                         flickr_server = photo("server"),
    104                                         flickr_secret = photo("secret")
     100                                title = str(photo("title")),
     101                                flickr_id = int(photo("id")),
     102                                flickr_owner = str(photo("owner")),
     103                                flickr_server = int(photo("server")),
     104                                flickr_secret = str(photo("secret")),
    105105                                )
    106106                                p.save()
    107                                
    108                 if (dupe or photos("page") == photos("pages")):   # If we hit a dupe or if we did the last page...
    109                         break
    110                 else:
    111                         cur_page += 1
     107
     108                                if (dupe or photos("page") == photos("pages")):   # If we hit a dupe or if we did the last page...
     109                                        break
     110                        else:
     111                                cur_page += 1
    112112}}}
    113113
Back to Top