本文整理汇总了Python中flickrapi.FlickrAPI.photosets_create方法的典型用法代码示例。如果您正苦于以下问题:Python FlickrAPI.photosets_create方法的具体用法?Python FlickrAPI.photosets_create怎么用?Python FlickrAPI.photosets_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.photosets_create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photosets_create [as 别名]
class TransFlickr:
extras = "original_format,date_upload,last_update"
def __init__(self, browserName):
self.fapi = FlickrAPI(flickrAPIKey, flickrSecret)
self.user_id = ""
# proceed with auth
# TODO use auth.checkToken function if available,
# and wait after opening browser.
print "Authorizing with flickr..."
log.info("authorizing with flickr...")
try:
self.authtoken = self.fapi.getToken(browser=browserName)
except:
print ("Can't retrieve token from browser %s" % browserName)
print ("\tIf you're behind a proxy server,"
" first set http_proxy environment variable.")
print "\tPlease close all your browser windows, and try again"
log.error(format_exc())
log.error("can't retrieve token from browser %s", browserName)
sys.exit(-1)
if self.authtoken == None:
print "Unable to authorize (reason unknown)"
log.error('not able to authorize; exiting')
sys.exit(-1)
#Add some authorization checks here(?)
print "Authorization complete."
log.info('authorization complete')
def uploadfile(self, filepath, taglist, bufData, mode):
#Set public 4(always), 1(public). Public overwrites f&f.
public = mode&1
#Set friends and family 4(always), 2(family), 1(friends).
friends = mode>>3 & 1
family = mode>>4 & 1
#E.g. 745 - 4:No f&f, but 5:public
#E.g. 754 - 5:friends, but not public
#E.g. 774 - 7:f&f, but not public
log.info("uploading file %s", filepath)
log.info(" data length: %s", len(bufData))
log.info(" taglist: %s", taglist)
log.info(" permissions: family %s, friends %s, public %s",
family, friends, public)
filename = os.path.splitext(os.path.basename(filepath))[0]
rsp = self.fapi.upload(filename=filepath, jpegData=bufData,
title=filename,
tags=taglist,
is_public=public and "1" or "0",
is_friend=friends and "1" or "0",
is_family=family and "1" or "0")
if rsp is None:
log.error("response None from attempt to write file %s", filepath)
log.error("will attempt recovery...")
recent_rsp = None
trytimes = 2
while(trytimes):
log.info("sleeping for 3 seconds...")
time.sleep(3)
trytimes -= 1
# Keep on trying to retrieve the recently uploaded photo, till we
# actually get the information, or the function throws an exception.
while(recent_rsp is None or not recent_rsp):
recent_rsp = self.fapi.photos_recentlyUpdated(
auth_token=self.authtoken, min_date='1', per_page='1')
pic = recent_rsp.photos[0].photo[0]
log.info('we are looking for %s', filename)
log.info('most recently updated pic is %s', pic['title'])
if filename == pic['title']:
id = pic['id']
log.info("file %s uploaded with photoid %s", filepath, id)
return id
log.error("giving up; upload of %s appears to have failed", filepath)
return None
else:
id = rsp.photoid[0].elementText
log.info("file %s uploaded with photoid %s", filepath, id)
return id
def put2Set(self, set_id, photo_id):
log.info("uploading photo %s to set id %s", photo_id, set_id)
rsp = self.fapi.photosets_addPhoto(auth_token=self.authtoken,
photoset_id=set_id, photo_id=photo_id)
if rsp:
log.info("photo uploaded to set")
else:
log.error(rsp.errormsg)
def createSet(self, path, photo_id):
log.info("creating set %s with primary photo %s", path, photo_id)
path, title = os.path.split(path)
rsp = self.fapi.photosets_create(auth_token=self.authtoken,
title=title, primary_photo_id=photo_id)
if rsp:
log.info("created set %s", title)
return rsp.photoset[0]['id']
else:
#.........这里部分代码省略.........