本文整理汇总了Python中smugpy.SmugMug.albums_getInfo方法的典型用法代码示例。如果您正苦于以下问题:Python SmugMug.albums_getInfo方法的具体用法?Python SmugMug.albums_getInfo怎么用?Python SmugMug.albums_getInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smugpy.SmugMug
的用法示例。
在下文中一共展示了SmugMug.albums_getInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_getInfo [as 别名]
#.........这里部分代码省略.........
while True:
data = f.read(block_size)
if not data:
break
md5.update(data)
return md5.hexdigest()
def _include_file(self, f, md5_sums):
if self._file_md5(f) in md5_sums:
print('skipping {0} (duplicate)'.format(f))
return False
return True
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_description):
album = self.get_album_by_name(album_name)
if album:
return album
return self.create_album(album_name, album_description)
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 create_album(self, album_name, album_description, privacy='unlisted'):
public = (privacy == 'public')
album_name = self._format_album_name(album_name)
album = self.smugmug.albums_create(Title=album_name, Public=public, SortMethod="DateTimeOriginal")
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 albums_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 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'])
示例3: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_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"])
示例4: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_getInfo [as 别名]
class SmugLine(object):
def __init__(self, api_key, email=None, password=None):
self.api_key = api_key
self.email = email
self.password = password
self.smugmug = SmugMug(
api_key=api_key,
api_version="1.2.2",
app_name="SmugLine")
self.login()
self.md5_sums = {}
def get_filter(self, media_type='images'):
if media_type == 'videos':
return VIDEO_FILTER
if media_type == 'images':
return IMG_FILTER
if media_type == 'all':
return ALL_FILTER
def upload_file(self, source_file, album):
album_id = album['id']
self.smugmug.images_upload(File=source_file, AlbumID=album_id)
def upload(self, source_folder, album_name, file_filter=IMG_FILTER):
album = self.get_or_create_album(album_name)
images = self.get_images_from_folder(source_folder, file_filter)
images = self._remove_duplicates(images, album)
for image in images:
print('uploading {0} -> {1}'.format(image, album_name))
self.upload_file(image, album)
def _get_remote_images(self, album, extras=None):
remote_images = self.smugmug.images_get(
AlbumID=album['id'],
AlbumKey=album['Key'],
Extras=extras)
return remote_images
def _get_md5_hashes_for_album(self, album):
remote_images = self._get_remote_images(album, 'MD5Sum')
md5_sums = [x['MD5Sum'] for x in remote_images['Album']['Images']]
self.md5_sums[album['id']] = md5_sums
return md5_sums
def _file_md5(self, filename, block_size=2**20):
md5 = hashlib.md5()
f = open(filename)
while True:
data = f.read(block_size)
if not data:
break
md5.update(data)
return md5.hexdigest()
def _include_file(self, f, md5_sums):
if self._file_md5(f) in md5_sums:
print('skipping {0} (duplicate)'.format(f))
return False
return True
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, 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') == album_name]
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 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)
#.........这里部分代码省略.........