本文整理汇总了Python中flickrapi.FlickrAPI.people_findByUsername方法的典型用法代码示例。如果您正苦于以下问题:Python FlickrAPI.people_findByUsername方法的具体用法?Python FlickrAPI.people_findByUsername怎么用?Python FlickrAPI.people_findByUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.people_findByUsername方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Importer
# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import people_findByUsername [as 别名]
class Importer(object):
def __init__(self):
self.flickr = FlickrAPI(FLICKR_KEY)
def get_photosets(self, username, filename=None):
filename = filename or username+'.json'
if os.path.exists(filename):
print "Looks like we already have information about your photos."
if raw_input("Refresh? (y/n): ").lower().startswith('n'):
return deserialize(open(filename).read())
print "Downloading information about your photos."
if '@' in username:
response = self.flickr.people_findByEmail(find_email=username)
else:
response = self.flickr.people_findByUsername(username=username)
nsid = response[0].get('nsid')
response = self.flickr.photosets_getList(user_id=nsid)
photosets = []
photo_ids = []
for ps in response[0]:
photoset = {'id': ps.get('id'),
'title': ps[0].text,
'description': ps[1].text,
'photos':[]}
photos_response = self.flickr.photosets_getPhotos(photoset_id=photoset['id'],
extras='url_o')
for pxml in photos_response[0]:
photo = {'id':pxml.get('id'),
'title':pxml.get('title')}
photoset['photos'].append(photo)
photo_ids.append(photo['id'])
print photoset['title'],'-',len(photoset['photos']),'photos'
photosets.append(photoset)
# get photos not in photosets
photos_response = self.flickr.photos_search(user_id=nsid, per_page=500)
photoset = {'id':'stream',
'title':'Flickr Stream',
'description':'Photos from my flickr stream',
'photos':[]}
for pxml in response[0]:
photo = {'id':pxml.get('id'),
'title':pxml.get('title')}
if photo['id'] not in photo_ids:
photoset['photos'].append(photo)
photo_ids.append(photo['id'])
if photoset['photos']:
print photoset['title'],'-',len(photoset['photos']),'photos'
photosets.append(photoset)
f = open(filename, "w")
f.write(serialize(photosets))
f.close()
return photosets
def download_images(self, photosets, directory):
print "Downloading your photos"
if not os.path.exists(directory):
os.mkdir(directory)
default = None
for photoset in photosets:
dirpath = os.path.join(directory, photoset['id']+' - '+photoset['title'])
if not os.path.exists(dirpath):
os.mkdir(dirpath)
for photo in photoset['photos']:
filename = os.path.join(dirpath, photo['id']+'.jpg')
if os.path.exists(filename):
if default is None:
print "Photo", photo['id'], "has already been downloaded."
default = raw_input("Download again? (y/n/Y/N) (capital to not ask again): ")
if default == 'n':
default = None
continue
elif default == 'N':
continue
elif default == 'y':
default = None
f = open(filename, 'w')
if not photo.get('url'):
try:
sizes_response = self.flickr.photos_getSizes(photo_id=photo['id'])
except:
print "Failed to download photo:", photo['id'], '... sorry!'
else:
photo['url'] = sizes_response[0][-1].get('source')
if photo.get('url'):
print "Downloading", photo['title'], 'from', photo['url']
remote = urllib2.urlopen(photo['url'])
f.write(remote.read())
f.close()
remote.close()
def upload_images(self, photosets, directory):
client = DivvyshotClient()
for photoset in photosets:
event_data = client.create_event(name=photoset['title'],
#.........这里部分代码省略.........