本文整理匯總了Python中flickrapi.FlickrAPI.photos_getExif方法的典型用法代碼示例。如果您正苦於以下問題:Python FlickrAPI.photos_getExif方法的具體用法?Python FlickrAPI.photos_getExif怎麽用?Python FlickrAPI.photos_getExif使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flickrapi.FlickrAPI
的用法示例。
在下文中一共展示了FlickrAPI.photos_getExif方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sync_photo
# 需要導入模塊: from flickrapi import FlickrAPI [as 別名]
# 或者: from flickrapi.FlickrAPI import photos_getExif [as 別名]
def sync_photo(photo):
flickr = FlickrAPI(API_KEY)
infos = flickr.photos_getInfo(photo_id=photo.flickr_id).find('photo')
exifs = flickr.photos_getExif(photo_id=photo.flickr_id).find('photo').findall('exif')
print "\tSyncing Photo: %s" % smart_str(photo.title)
for exif in exifs:
if exif.attrib['label'] == 'Aperture' and exif.attrib['tag'] == 'FNumber':
photo.aperture = exif.find('clean').text
if exif.attrib['label'] == 'Model' and exif.attrib['tag'] == 'Model':
photo.camera = exif.find('raw').text
if exif.attrib['label'] == 'Exposure' and exif.attrib['tag'] == 'ExposureTime':
photo.exposure = exif.find('raw').text
if exif.attrib['label'] == 'ISO Speed' and exif.attrib['tag'] == 'ISO':
photo.iso = exif.find('raw').text
if exif.attrib['label'] == 'Lens' and exif.attrib['tag'] == 'Lens':
photo.lens = exif.find('raw').text
photo.posted_date = datetime.fromtimestamp(float(infos.find('dates').attrib['posted']))
photo.description = infos.find('description').text
tags = infos.find('tags').findall('tag')
photo.tags.clear() # clear all previous tags if present
#Save photo prior saving the many to many relationship with tags
try:
photo.save()
except:
print '\t\tFail to Save Photo: %s' % smart_str(photo.title)
return photo
for tag in tags:
tag_id = tag.text[0:31]
print '\t\tFound tag: %s' % tag_id
try:
t = Tag.objects.get(pk=tag_id)
photo.tags.add(t)
except:
t = Tag(name=tag.text, raw=tag.attrib['raw'])
t.save()
photo.tags.add(t)
#print '[Flickr] Exif for %s: %s, %s, %s' % (photo.title, photo.lens, photo.iso, photo.posted_date)
return photo