本文整理汇总了Python中smugpy.SmugMug.images_delete方法的典型用法代码示例。如果您正苦于以下问题:Python SmugMug.images_delete方法的具体用法?Python SmugMug.images_delete怎么用?Python SmugMug.images_delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smugpy.SmugMug
的用法示例。
在下文中一共展示了SmugMug.images_delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_delete [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 images_delete [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 images_delete [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 images_delete [as 别名]
#.........这里部分代码省略.........
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)
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(
os.path.join(root, name) for name in filenames \
if img_filter.match(name))
return matches
def _set_email_and_password(self):
if self.email is None:
self.email = raw_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'])