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


Python SmugMug.subcategories_get方法代码示例

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


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

示例1: SmugLine

# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import subcategories_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):
        result = "-1"
        retries = 0
        while (result != "smugmug.images.upload") and (retries < 5):
            try:
                retries = retries + 1
                if result == "-2":
                    print ("Exception, retrying (attempt {0}).".format(retries))
                    time.sleep(retries * 3)
                rsp = self.smugmug.images_upload(AlbumID=album["id"], **image)
                result = rsp["method"]
            except Exception as inst:
                print inst
                result = "-2"
                pass
        if result == "-2":
            print ("ERROR: File upload failed.")

    # 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 set_file_timestamp(self, filename, image):
        # apply the image date
        image_info = self.get_image_info(image)
        timestamp = time.strptime(image_info["Image"]["Date"], "%Y-%m-%d %H:%M:%S")
        t = time.mktime(timestamp)
        os.utime(filename, (t, t))

    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 account_folder_number(self, source_folder):
        images = self.get_images_from_folder(source_folder, file_filter)
        return len(images)

    def upload_folder_structure(self, album_title, source_folder, file_filter, uploaded_files, total_files):
        album_name = source_folder.replace("./", "").split("/", 1)[1]
        subcategory_name = source_folder.replace("./", "").split("/", 1)[0]
        categories = self.smugmug.categories_get()
        category = None
        for candidate_category in categories["Categories"]:
            if candidate_category["Name"] == album_title:
                category = candidate_category

        if category is None:
            category = self.smugmug.categories_create(Name=album)["Category"]

        subcategories = self.smugmug.subcategories_get(CategoryID=category["id"])
        subcategory = None
        for candidate_subcategory in subcategories["SubCategories"]:
            if candidate_subcategory["Name"] == subcategory_name:
#.........这里部分代码省略.........
开发者ID:ds20,项目名称:smugline,代码行数:103,代码来源:smugline.py


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