当前位置: 首页>>代码示例>>Python>>正文


Python SmugMug.albums_create方法代码示例

本文整理汇总了Python中smugpy.SmugMug.albums_create方法的典型用法代码示例。如果您正苦于以下问题:Python SmugMug.albums_create方法的具体用法?Python SmugMug.albums_create怎么用?Python SmugMug.albums_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smugpy.SmugMug的用法示例。


在下文中一共展示了SmugMug.albums_create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_create [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'])
开发者ID:ykorabelnikov,项目名称:smugline,代码行数:104,代码来源:smugline.py

示例2: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_create [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'])
开发者ID:pombreda,项目名称:smugline,代码行数:104,代码来源:smugline.py

示例3: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_create [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"])
开发者ID:ds20,项目名称:smugline,代码行数:104,代码来源:smugline.py

示例4: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_create [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)
#.........这里部分代码省略.........
开发者ID:john-peterson,项目名称:smugline,代码行数:103,代码来源:smugline.py


注:本文中的smugpy.SmugMug.albums_create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。