本文整理汇总了Python中flickrapi.FlickrAPI.test_login方法的典型用法代码示例。如果您正苦于以下问题:Python FlickrAPI.test_login方法的具体用法?Python FlickrAPI.test_login怎么用?Python FlickrAPI.test_login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.test_login方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import test_login [as 别名]
class Offlickr:
def __init__(
self,
key,
secret,
httplib=None,
dryrun=False,
verbose=False,
):
"""Instantiates an Offlickr object
An API key is needed, as well as an API secret"""
self.__flickrAPIKey = key
self.__flickrSecret = secret
self.__httplib = httplib
# Get authentication token
# note we must explicitly select the xmlnode parser to be compatible with FlickrAPI 1.2
self.fapi = FlickrAPI(self.__flickrAPIKey, self.__flickrSecret,
format='xmlnode')
(token, frob) = self.fapi.get_token_part_one()
if not token:
raw_input('Press ENTER after you authorized this program')
self.fapi.get_token_part_two((token, frob))
self.token = token
test_login = self.fapi.test_login()
uid = test_login.user[0]['id']
self.flickrUserId = uid
self.dryrun = dryrun
self.verbose = verbose
def __testFailure(self, rsp):
"""Returns whether the previous call was successful"""
if rsp['stat'] == 'fail':
print 'Error!'
return True
else:
return False
def getPhotoList(self, dateLo, dateHi):
"""Returns a list of photo given a time frame"""
n = 0
flickr_max = 500
photos = []
print 'Retrieving list of photos'
while True:
if self.verbose:
print 'Requesting a page...'
n = n + 1
rsp = self.fapi.photos_search(
api_key=self.__flickrAPIKey,
auth_token=self.token,
user_id=self.flickrUserId,
per_page=str(flickr_max),
page=str(n),
min_upload_date=dateLo,
max_upload_date=dateHi,
)
if self.__testFailure(rsp):
return None
if rsp.photos[0]['total'] == '0':
return None
photos += rsp.photos[0].photo
if self.verbose:
print ' %d photos so far' % len(photos)
if len(photos) >= int(rsp.photos[0]['total']):
break
return photos
def getGeotaggedPhotoList(self, dateLo, dateHi):
"""Returns a list of photo given a time frame"""
n = 0
flickr_max = 500
photos = []
print 'Retrieving list of photos'
while True:
if self.verbose:
print 'Requesting a page...'
n = n + 1
rsp = \
self.fapi.photos_getWithGeoData(api_key=self.__flickrAPIKey,
auth_token=self.token, user_id=self.flickrUserId,
per_page=str(flickr_max), page=str(n))
if self.__testFailure(rsp):
return None
if rsp.photos[0]['total'] == '0':
return None
photos += rsp.photos[0].photo
if self.verbose:
print ' %d photos so far' % len(photos)
if len(photos) >= int(rsp.photos[0]['total']):
break
#.........这里部分代码省略.........