本文整理汇总了Python中smugpy.SmugMug.images_getInfo方法的典型用法代码示例。如果您正苦于以下问题:Python SmugMug.images_getInfo方法的具体用法?Python SmugMug.images_getInfo怎么用?Python SmugMug.images_getInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smugpy.SmugMug
的用法示例。
在下文中一共展示了SmugMug.images_getInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_getInfo [as 别名]
#.........这里部分代码省略.........
print('skipping {0} (duplicate)'.format(f))
return False
return True
except IOError as err:
# see https://github.com/PyCQA/pylint/issues/165
# pylint: disable=unpacking-non-sequence
errno, strerror = err
print('I/O Error({0}): {1}...skipping'.format(errno, strerror))
return False
def _remove_duplicates(self, images, album):
md5_sums = self._get_md5_hashes_for_album(album)
return [x for x in images if self._include_file(x.get('File'), md5_sums)]
def get_albums(self):
albums = self.smugmug.albums_get(NickName=self.nickname)
return albums
def list_albums(self):
print('available albums:')
for album in self.get_albums()['Albums']:
if album['Title']:
print(album['Title'].encode('utf-8'))
def get_or_create_album(self, album_name):
album = self.get_album_by_name(album_name)
if album:
return album
return self.create_album(album_name)
def get_album_by_name(self, album_name):
albums = self.get_albums()
try:
matches = [x for x in albums['Albums'] \
if x.get('Title').lower() == album_name.lower()]
return matches[0]
except:
return None
def _format_album_name(self, album_name):
return album_name[0].upper() + album_name[1:]
def get_album_info(self, album):
return self.smugmug.albums_getInfo(AlbumID=album['id'], AlbumKey=album['Key'])
def get_image_info(self, image):
return self.smugmug.images_getInfo(ImageKey=image['Key'])
def create_album(self, album_name, privacy='unlisted'):
public = (privacy == 'public')
album_name = self._format_album_name(album_name)
album = self.smugmug.albums_create(Title=album_name, Public=public)
album_info = self.get_album_info(album['Album'])
print('{0} album {1} created. URL: {2}'.format(
privacy,
album_name,
album_info['Album']['URL']))
return album_info['Album']
def get_images_from_folder(self, folder, img_filter=IMG_FILTER):
matches = []
for root, dirnames, filenames in os.walk(folder):
matches.extend(
{'File': os.path.join(root, name)} for name in filenames \
if img_filter.match(name))
return matches
def _set_email_and_password(self):
# for python2
try:
input = raw_input
except NameError:
pass
if self.email is None:
self.email = input('Email address: ')
if self.password is None:
self.password = getpass.getpass()
def login(self):
self._set_email_and_password()
self.user_info = self.smugmug.login_withPassword(
EmailAddress=self.email,
Password=self.password)
self.nickname = self.user_info['Login']['User']['NickName']
return self.user_info
def _delete_image(self, image):
print('deleting image {0} (md5: {1})'.format(image['FileName'],
image['MD5Sum']))
self.smugmug.images_delete(ImageID=image['id'])
def clear_duplicates(self, album_name):
album = self.get_album_by_name(album_name)
remote_images = self._get_remote_images(album, 'MD5Sum,FileName')
md5_sums = []
for image in remote_images['Album']['Images']:
if image['MD5Sum'] in md5_sums:
self._delete_image(image)
md5_sums.append(image['MD5Sum'])
示例2: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_getInfo [as 别名]
#.........这里部分代码省略.........
return md5.hexdigest()
def _include_file(self, f, md5_sums):
try:
if self._file_md5(f) in md5_sums:
print ("skipping {0} (duplicate)".format(f))
return False
return True
except IOError as err:
errno, strerror = err
print ("I/O Error({0}): {1}...skipping".format(errno, strerror))
return False
def _remove_duplicates(self, images, album):
md5_sums = self._get_md5_hashes_for_album(album)
return [x for x in images if self._include_file(x.get("File"), md5_sums)]
def get_albums(self):
albums = self.smugmug.albums_get(NickName=self.nickname)
return albums
def list_albums(self):
print ("available albums:")
for album in self.get_albums()["Albums"]:
if album["Title"]:
print (album["Title"])
def get_or_create_album(self, album_name):
album = self.get_album_by_name(album_name)
if album:
return album
return self.create_album(album_name)
def get_album_by_name(self, album_name):
albums = self.get_albums()
try:
matches = [x for x in albums["Albums"] if x.get("Title").lower() == album_name.lower()]
return matches[0]
except:
return None
def _format_album_name(self, album_name):
return album_name[0].upper() + album_name[1:]
def get_album_info(self, album):
return self.smugmug.albums_getInfo(AlbumID=album["id"], AlbumKey=album["Key"])
def get_image_info(self, image):
return self.smugmug.images_getInfo(ImageKey=image["Key"])
def create_album(self, album_name, privacy="unlisted"):
public = privacy == "public"
album_name = self._format_album_name(album_name)
album = self.smugmug.albums_create(Title=album_name, Public=public)
album_info = self.get_album_info(album["Album"])
return album_info["Album"]
def create_album(self, album_name, privacy, category):
public = privacy == "public"
album_name = self._format_album_name(album_name)
album = self.smugmug.albums_create(Title=album_name, Public=public, CategoryID=category)
album_info = self.get_album_info(album["Album"])
return album_info["Album"]
def get_images_from_folder(self, folder, img_filter=IMG_FILTER):
matches = []
for root, dirnames, filenames in os.walk(folder):
matches.extend({"File": os.path.join(root, name)} for name in filenames if img_filter.match(name))
return matches
def _set_email_and_password(self):
# for python2
try:
input = raw_input
except NameError:
pass
if self.email is None:
self.email = input("Email address: ")
if self.password is None:
self.password = getpass.getpass()
def login(self):
self._set_email_and_password()
self.user_info = self.smugmug.login_withPassword(EmailAddress=self.email, Password=self.password)
self.nickname = self.user_info["Login"]["User"]["NickName"]
return self.user_info
def _delete_image(self, image):
print ("deleting image {0} (md5: {1})".format(image["FileName"], image["MD5Sum"]))
self.smugmug.images_delete(ImageID=image["id"])
def clear_duplicates(self, album_name):
album = self.get_album_by_name(album_name)
remote_images = self._get_remote_images(album, "MD5Sum,FileName")
md5_sums = []
for image in remote_images["Album"]["Images"]:
if image["MD5Sum"] in md5_sums:
self._delete_image(image)
md5_sums.append(image["MD5Sum"])
示例3: __init__
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_getInfo [as 别名]
class SmugMugClient:
def __init__(self, api_key, gallery, link_type, nickname):
self.smugmug = SmugMug(api_key=api_key, api_version="1.3.0", app_name="TwiMug")
self.gallery = gallery
self.link_type = link_type
self.nickname = nickname
def get_albums(self):
albums = self.smugmug.albums_get(NickName=self.nickname)
return albums
def get_album_info(self, album_name):
for album in self.get_albums()["Albums"]:
if album["Title"] == album_name:
return album
def get_images_for_album(self, album_id, album_key):
images = self.smugmug.images_get(AlbumID=album_id, AlbumKey=album_key)
return images
def get_image_urls(self, image_id, image_key):
urls = self.smugmug.images_getURLs(ImageID=image_id, ImageKey=image_key)
return urls
def get_last_image_urls(self):
last_image = self.get_last_image_info()
urls = self.get_image_urls(last_image["id"], last_image["Key"])
return urls
def get_last_image_info(self):
album = self.get_album_info(self.gallery)
images = self.get_images_for_album(album["id"], album["Key"])
last_image = images["Album"]["Images"][-1]
return last_image
def get_last_image_extended_info(self):
last_image = self.get_last_image_info()
extended_info = self.smugmug.images_getInfo(ImageID=last_image["id"], ImageKey=last_image["Key"])
return extended_info["Image"]
def get_last_image_url(self):
urls = self.get_last_image_urls()
return urls["Image"][self.link_type]
def save_last_image_url(self):
url = self.get_last_image_url()
with open("last_image_url", "w") as file:
file.write(url)
def load_last_image_url(self):
url = ""
with open("last_image_url", "r") as file:
url = file.readline()
return url