Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (c) 2008 Brian Zimmer <bzimmer@ziclix.com> 2 # 3 # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 # this software and associated documentation files (the "Software"), to deal in 5 # the Software without restriction, including without limitation the rights to 6 # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 # of the Software, and to permit persons to whom the Software is furnished to do 8 # so, subject to the following conditions: 9 # 10 # The above copyright notice and this permission notice shall be included in all 11 # copies or substantial portions of the Software. 12 # 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 # SOFTWARE. 20 21 import pysmug 22 import collections2515727 """Return the tree of categories and sub-categories. 28 29 The format of the response tree:: 30 31 {u'Categories': [{u'Name': u'Other', 'SubCategories': {}, u'id': 0}, 32 {u'Name': u'Airplanes', 'SubCategories': {}, u'id': 41}, 33 {u'Name': u'Animals', 'SubCategories': {}, u'id': 1}, 34 {u'Name': u'Aquariums', 'SubCategories': {}, u'id': 25}, 35 {u'Name': u'Architecture', 'SubCategories': {}, u'id': 2}, 36 {u'Name': u'Art', 'SubCategories': {}, u'id': 3}, 37 {u'Name': u'Arts and Crafts', 'SubCategories': {}, u'id': 43}, 38 ..., 39 ], 40 u'method': u'pysmug.categories.getTree', 41 u'stat': u'ok'} 42 """ 43 b = self.batch() 44 b.categories_get() 45 b.subcategories_getAll() 46 47 methods = dict() 48 for params, results in b(): 49 methods[params["method"]] = results 50 51 subcategories = collections.defaultdict(list) 52 for subcategory in methods["smugmug.subcategories.getAll"]["SubCategories"]: 53 category = subcategory.pop("Category") 54 subcategories[category["id"]].append(subcategory) 55 56 categories = methods["smugmug.categories.get"]["Categories"] 57 for category in categories: 58 category["SubCategories"] = subcategories.get(category["id"], {}) 59 60 return {u"method":u"pysmug.categories.getTree", u"Categories":categories, u"stat":u"ok"}61 62 @pysmug.smugmug_keywords64 """Returns the full details of an album including EXIF data for all images. It 65 is the composition of calls to C{albums_getInfo}, C{images_getInfo} and 66 C{images_getEXIF} where the C{images_*} calls are done in batch. The primary purpose 67 for this method is to provide easy access to a full album worth of metadata quickly. 68 69 The format of the response tree:: 70 71 {'Album': {'Attribute1': 'Value1', 72 'AttributeN': 'ValueN', 73 'Images': [{'EXIF': {'EXIFAttribute1': 'EXIFValue1', 74 'EXIFAttributeN': 'EXIFValueN'}, 75 'ImageAttribute1': 'ImageValue1', 76 'ImageAttributeN': 'ImageAttributeN'}, 77 {'EXIF': {'EXIFAttribute1': 'EXIFValue1', 78 'EXIFAttributeN': 'EXIFValueN'}, 79 'ImageAttribute1': 'ImageValue1', 80 'ImageAttributeN': 'ImageAttributeN'}]}, 81 'Statistics': {}, 82 'method': 'pysmug.albums.details', 83 'stat': 'ok'} 84 85 @keyword albumId: the id of the album to query 86 @keyword albumKey: the key of the album to query 87 @keyword exif: returns EXIF metadata about each image 88 @return: a dictionary of the album and image details 89 """ 90 albumId = kwargs.get("AlbumID") 91 albumKey = kwargs.get("AlbumKey") 92 exif = kwargs.get("Exif") 93 album = self.albums_getInfo(albumId=albumId, albumKey=albumKey) 94 images = self.images_get(albumId=albumId, albumKey=albumKey) 95 96 # map 97 b = self.batch() 98 for imageId, imageKey in ((image["id"], image["Key"]) for image in images["Images"]): 99 # add each image to the batch 100 b.images_getInfo(imageID=imageId, imageKey=imageKey) 101 if exif: 102 b.images_getEXIF(imageID=imageId, imageKey=imageKey) 103 104 # combine 105 responses = collections.defaultdict(dict) 106 for (params, value) in b(): 107 imageIdKey = (params["ImageID"], params["ImageKey"]) 108 responses[imageIdKey][params["method"]] = value 109 110 # reduce 111 album[u"Album"][u"Images"] = images = [] 112 for value in responses.values(): 113 img = value["smugmug.images.getInfo"]["Image"] 114 if exif: 115 img[u"EXIF"] = value["smugmug.images.getEXIF"]["Image"] 116 images.append(img) 117 118 # return 119 album.update({u"method":u"pysmug.albums.details", u"stat":u"ok", u"Statistics":{}}) 120 return album121123 """Returns a generator of albums with ImageCount == 0. 124 125 @return: a generator of albums with an image count == 0 126 """ 127 b = self.batch() 128 for album in self.albums_get()["Albums"]: 129 b.albums_getInfo(albumId=album["id"], albumKey=album["Key"]) 130 return (info["Album"] for params, info in b() if info["Album"]["ImageCount"] == 0)131133 """Returns a generator of categories or subcategories with no 134 albums. 135 136 @return: a generator of [sub]categories with no associated albums 137 """ 138 used = dict() 139 albums = self.albums_get()["Albums"] 140 for album in albums: 141 category = album["Category"] 142 used[("category", category["id"])] = category 143 subcategory = album.get("SubCategory", None) 144 if subcategory: 145 used[("subcategory", album["SubCategory"]["id"])] = subcategory 146 tree = self.categories_getTree() 147 for c in tree["Categories"]: 148 cid = ("category", c["id"]) 149 if not cid in used: 150 c["Type"] = "Category" 151 yield c 152 for s in c["SubCategories"]: 153 sid = ("subcategory", s["id"]) 154 if not sid in used: 155 s["Type"] = "SubCategory" 156 yield s
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue May 13 19:45:59 2008 | http://epydoc.sourceforge.net |