本文整理匯總了Python中flickrapi.FlickrAPI.people_getPublicPhotos方法的典型用法代碼示例。如果您正苦於以下問題:Python FlickrAPI.people_getPublicPhotos方法的具體用法?Python FlickrAPI.people_getPublicPhotos怎麽用?Python FlickrAPI.people_getPublicPhotos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.people_getPublicPhotos方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sync_flickr
# 需要導入模塊: from flickrapi import FlickrAPI [as 別名]
# 或者: from flickrapi.FlickrAPI import people_getPublicPhotos [as 別名]
def sync_flickr(*args, **kwargs):
u = Update(updated_date=datetime.now())
flickr = FlickrAPI(API_KEY, API_SECRET)
flickr_photos = []
for flickr_id in args:
page = 1
while page > 0:
request = flickr.people_getPublicPhotos(user_id=flickr_id, per_page=100, page=page, extras='last_update')
pages = int(request.find('photos').attrib['pages'])
photos = request.find('photos').findall('photo')
#Add photos to all list
flickr_photos.extend(photos)
print "[Flickr] - Processing page: %d/%d User: [%s]" % (page,pages,flickr_id)
for photo in photos:
photo_id = photo.attrib['id']
# update photo if already in db
try:
p = Photo.objects.get(flickr_id = photo_id)
updated_date = datetime.fromtimestamp(float(photo.attrib['lastupdate']))
if p.updated_date < updated_date:
p.title = photo.attrib['title']
p.updated_date = updated_date
p.farm = int(photo.attrib['farm'])
p.server = int(photo.attrib['server'])
p.secret = photo.attrib['secret']
print '[Flickr] Updating Photo: %s' % smart_str(photo.title)
sync_photo(p)
#otherwise create and save
except:
p = Photo(
flickr_id = photo_id,
server = int(photo.attrib['server']),
secret = photo.attrib['secret'],
title = photo.attrib['title'],
farm = int(photo.attrib['farm']),
added_date = datetime.now(),
updated_date= datetime.fromtimestamp(float(photo.attrib['lastupdate'])),
#set = photoset
)
print '[Flickr] - Adding New Photo: %s' % (smart_str(p.title))
sync_photo(p)
u.updated = True
if page == pages:
page = 0
else:
page = page + 1
#Update deleted photos if needed
sync_deleted_photos(flickr_photos)
print "[Flickr] - Done Updating"
u.save()