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


Python SmugMug.images_get方法代码示例

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


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

示例1: get

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [as 别名]
    def get(self, albumID, albumKey):
        """Fuction to handle GET requests."""
        html = xhtml.HTML(self)

        # Fetch the application settings
        prefs = AppPrefs().fetch()

        # Check to see if the user preferences object has anything of value in it
        if not getattr(prefs, "api_key"):
            self.redirect("/static/unconfig.html")
            return

        html.header(prefs.title)

        # So far, so good.  Try connecting to SmugMug.
        try:
            smugmug = SmugMug(api_key=prefs.api_key, api_version="1.3.0", app_name=prefs.app_name)
            images = smugmug.images_get(AlbumID=albumID, AlbumKey=albumKey)
        except Exception, e:
            # Hmmm... something's not right.
            self.response.out.write("There was a problem connecting to SmugMug: %s" % e)
            return
开发者ID:scottwallacesh,项目名称:smughost,代码行数:24,代码来源:album.py

示例2: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [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, album, image):
        self.smugmug.images_upload(AlbumID=album['id'], **image)

    def upload_json(self, source_folder, json_file):
        images = json.load(open(json_file))

        # prepend folder
        for image in images:
            image['File'] = source_folder + image['File']

        # group by album
        groups = []
        images.sort(key=lambda x: x['AlbumName'])
        for k, g in groupby(images, key=lambda x: x['AlbumName']):
            groups.append(list(g))

        for group in groups:
            album_name = group[0]['AlbumName']
            album = self.get_or_create_album(album_name)
            self._upload(group, album_name, album)

    def upload_folder(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)
        self._upload(images, album_name, album)
        
    def upload_with_folders(self, source_folder, file_filter=IMG_FILTER):
        excludes = ['.DS_Store', '.git', 'desktop.ini']
        
        for root, dirnames, filenames in os.walk(source_folder, topdown=True):
            # exclude some common "hidden" files and dirs
            dirnames[:] = [d for d in dirnames if d not in excludes] 
            filenames[:] = [f for f in filenames if f not in excludes]
            
            # skip the root
            if (root != source_folder):
                
                # if there are NO subfolders and there are images, create SmugMug album
                # named root and upload all filenames
                if (not dirnames and filenames):
                    album_description = root[len(source_folder) + 1:]
                    album_name = album_description
                    # album_name = album_description[album_description.find('/') + 1:]
                    album = self.get_or_create_album(album_name, "")
                    images = self.get_images_from_folder(root, file_filter)
                    self._upload(images, album_name, album)
        return

    def _upload(self, images, album_name, album):
        images = self._remove_duplicates(images, album)
        for image in images:
            print('uploading {0} -> {1}'.format(image, album_name))
            self.upload_file(album, image)

    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, 'rb')
        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))
#.........这里部分代码省略.........
开发者ID:ykorabelnikov,项目名称:smugline,代码行数:103,代码来源:smugline.py

示例3: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [as 别名]

#.........这里部分代码省略.........
                subcategory = candidate_subcategory

        if subcategory is None:
            subcategory = self.smugmug.subcategories_create(Name=subcategory_name, CategoryID=category["id"])[
                "SubCategory"
            ]

        album = self.create_album(album_name, "unlisted", subcategory["id"])
        images = self.get_images_from_folder(source_folder, file_filter)
        self._upload(images, album_name, album, uploaded_files, total_files)

    def download_album(self, album_name, dest_folder, file_filter=IMG_FILTER):
        album = self.get_album_by_name(album_name)
        if album is None:
            print ("Album {0} not found".format(album_name))
            return
        images = self._get_images_for_album(album, file_filter)
        self._download(images, dest_folder)

    def _upload(self, images, album_name, album, uploaded_files, total_files):
        images = self._remove_duplicates(images, album)
        for image in images:
            print ("[{0:03d}/{1:03d}] Uploading {2}".format(uploaded_files, total_files, image))
            self.upload_file(album, image)
            uploaded_files = uploaded_files + 1

    def _download(self, images, dest_folder):
        for img in images:
            print ("downloading {0} -> {1}".format(img["FileName"], dest_folder))
            filename = self.download_file(img["OriginalURL"], dest_folder, img["FileName"])
            self.set_file_timestamp(filename, img)

    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 _get_images_for_album(self, album, file_filter=IMG_FILTER):
        extras = "FileName,OriginalURL"
        images = self._get_remote_images(album, extras)["Album"]["Images"]

        for image in [img for img in images if file_filter.match(img["FileName"])]:
            yield image

    def _file_md5(self, filename, block_size=2 ** 20):
        md5 = hashlib.md5()
        f = open(filename, "rb")
        while True:
            data = f.read(block_size)
            if not data:
                break
            md5.update(data)
        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:
开发者ID:ds20,项目名称:smugline,代码行数:70,代码来源:smugline.py

示例4: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [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, album, image):
        self.smugmug.images_upload(AlbumID=album['id'], **image)

    # source: http://stackoverflow.com/a/16696317/305019
    def download_file(self, url, folder, filename=None):
        local_filename = os.path.join(folder, filename or url.split('/')[-1])
        if os.path.exists(local_filename):
            print('{0} already exists...skipping'.format(local_filename))
            return
        r = requests.get(url, stream=True)
        with open(local_filename, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk: # filter out keep-alive new chunks
                    f.write(chunk)
                    f.flush()
        return local_filename

    def upload_json(self, source_folder, json_file):
        images = json.load(open(json_file))

        # prepend folder
        for image in images:
            image['File'] = source_folder + image['File']

        # group by album
        groups = []
        images.sort(key=lambda x: x['AlbumName'])
        for k, g in groupby(images, key=lambda x: x['AlbumName']):
            groups.append(list(g))

        for group in groups:
            album_name = group[0]['AlbumName']
            album = self.get_or_create_album(album_name)
            self._upload(group, album_name, album)

    def upload_folder(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)
        self._upload(images, album_name, album)

    def download_album(self, album_name, dest_folder, file_filter=IMG_FILTER):
        album = self.get_album_by_name(album_name)
        if album is None:
            print('Album {0} not found'.format(album_name))
            return
        images = self._get_images_for_album(album, file_filter)
        self._download(images, dest_folder)

    def _upload(self, images, album_name, album):
        images = self._remove_duplicates(images, album)
        for image in images:
            print('uploading {0} -> {1}'.format(image, album_name))
            self.upload_file(album, image)

    def _download(self, images, dest_folder):
        for img in images:
            print('downloading {0} -> {1}'.format(img['FileName'], dest_folder))
            self.download_file(img['OriginalURL'], dest_folder, img['FileName'])

    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 _get_images_for_album(self, album, file_filter=IMG_FILTER):
        extras = 'FileName,OriginalURL'
        images = self._get_remote_images(album, extras)['Album']['Images']

        for image in [img for img in images \
                    if file_filter.match(img['FileName'])]:
            yield image

#.........这里部分代码省略.........
开发者ID:pombreda,项目名称:smugline,代码行数:103,代码来源:smugline.py

示例5: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [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

示例6: raw_input

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [as 别名]
    smugmug.auth_getRequestToken()
    raw_input("Authorize app at %s\n\nPress Enter when complete.\n" % (smugmug.authorize(access='Full')))
    response = smugmug.auth_getAccessToken()
    print("  token: %s" % response['Auth']['Token']['id'])
    print("  secret: %s" % response['Auth']['Token']['Secret'])
    print("Enter these values into smugmuglinkgen.conf to skip this auth process the next time around.")

# the real work starts here
albums = smugmug.albums_get(NickName=USERNAME)
for album in albums['Albums']:
    if arguments['list']:
        print(album['Title'])
    else:
        if arguments['<albumname>'] in album['Title']:
            print("Processing %s, %s" % (album['id'], album['Title']))
            images = smugmug.images_get(AlbumID=album['id'], AlbumKey=album['Key'], Heavy=True)
            for image in images['Album']['Images']:
                original_url = image['OriginalURL']

                if image['Width'] > image['Height']:
                    display_url = image['XLargeURL']
                else:
                    display_url = image['X2LargeURL']

                if arguments['bbcode']:
                    output = '[url=%s][img]%s[/img][/url]' % (original_url, display_url)
                else:
                    output = '<a href="%s"><img src="%s"/></a>' % (original_url, display_url)
                    if arguments['figures']:
                        output = '<figure>%s</figure>' % output
开发者ID:stacybrock,项目名称:smugmuglinkgen,代码行数:32,代码来源:smugmuglinkgen.py

示例7: __init__

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import images_get [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
开发者ID:dyon,项目名称:TwiMug,代码行数:67,代码来源:SmugMugClient.py


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