

def fetch(account):
    '\n    Fetch a list of recent photos from the flickr servers using the supplied\n    credentials, and save them to the DB.\n    \n    Returns a tuple containing the number of items created, and the number of \n    items updated or skipped.\n    '
    import flickrapi
    items_existing = 0
    items_created = 0
    api = flickrapi.FlickrAPI(account.api_key, format='etree')
    if (not account.userid):
        try:
            account.userid = api.people_findByUsername(username=account.username).find('user').attrib['nsid']
            account.save()
        except:
            return (0, 0)
    extras = 'date_upload, date_taken'
    per_page = 500
    if (FlickrPhoto.objects.count() > 0):
        latestphoto = FlickrPhoto.objects.latest()
        timestamp = calendar.timegm(latestphoto.published.timetuple())
        recentphotos = api.photos_search(user_id=account.userid, per_page=per_page, min_upload_date=timestamp, extras=extras)
    else:
        recentphotos = api.people_getPublicPhotos(user_id=account.userid, per_page=per_page, extras=extras)
    iter = recentphotos.getiterator('photo')
    for photo in iter:
        upload_date = datetime.fromtimestamp(int(photo.attrib['dateupload']))
        (entry, created) = FlickrPhoto.objects.get_or_create(account=account, photo_id=photo.attrib['id'], published=upload_date)
        if created:
            entry.title = photo.attrib['title']
            entry.link = ('http://flickr.com/photos/%s/%s' % (account.userid, entry.photo_id))
            base_url = ('http://farm%s.static.flickr.com/%s/%s_%s' % (photo.attrib['farm'], photo.attrib['server'], entry.photo_id, photo.attrib['secret']))
            entry.square_thumb_link = (base_url + '_s.jpg')
            entry.image_500px_link = (base_url + '.jpg')
            entry.taken_on_date = parser.parse(photo.attrib['datetaken'])
            entry.save()
            items_created += 1
        else:
            items_existing += 1
    return (items_created, items_existing)

dataset/ETHPy150Open idan/djangregator/djangregator/services/flickr.py fetch/original