当前位置: 首页>>代码示例>>Python>>正文


Python FlickrAPI.people_getPublicPhotos方法代码示例

本文整理汇总了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()
开发者ID:apouche,项目名称:yogikarma,代码行数:67,代码来源:models.py


注:本文中的flickrapi.FlickrAPI.people_getPublicPhotos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。