本文整理汇总了Python中flickrapi.FlickrAPI.photos_getWithGeoData方法的典型用法代码示例。如果您正苦于以下问题:Python FlickrAPI.photos_getWithGeoData方法的具体用法?Python FlickrAPI.photos_getWithGeoData怎么用?Python FlickrAPI.photos_getWithGeoData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.photos_getWithGeoData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photos_getWithGeoData [as 别名]
def run(write_directory, exiv2_file_path, from_date):
"""Fetch all geotagged photos and write exiv2 script for them.
Retrieve all geotagged photos taken since `from_date` to
`write_directory` and write a set of exiv2(1) commands storing
geotags in EXIF to `exiv2_file_path`.
`from_date` is a string YYYY-MM-DD, `write_directory` and
`exiv2_file_path` are valid directory and file names,
respectively.
"""
exiv2_file = open(exiv2_file_path, 'w')
# Start flickring
flickr = FlickrAPI(API_KEY, API_SECRET, format='etree')
# Authorize
(token, frob) = flickr.get_token_part_one(perms='read')
if not token: raw_input('Press ENTER after you authorized this program')
flickr.get_token_part_two((token, frob))
print 'Retrieving list of geotagged photos taken since %s...' % from_date
photos = flickr.photos_getWithGeoData(min_date_taken=from_date).getiterator('photo')
# Retrieve photo to `write_directory`, write exiv2 commands to
# scriptfile.
for photo in photos:
title, url, location = get_photo_data(flickr, photo)
print 'Retrieving photo %s...' % title
filename, headers = urlretrieve(url, os.path.join(write_directory, \
os.path.basename(url)))
write_location_commands(os.path.abspath(filename), location, exiv2_file)
示例2: __init__
# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photos_getWithGeoData [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
#.........这里部分代码省略.........