本文整理汇总了Python中smugpy.SmugMug.albums_get方法的典型用法代码示例。如果您正苦于以下问题:Python SmugMug.albums_get方法的具体用法?Python SmugMug.albums_get怎么用?Python SmugMug.albums_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smugpy.SmugMug
的用法示例。
在下文中一共展示了SmugMug.albums_get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestApi130
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
class TestApi130(unittest.TestCase):
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp')
def test_anonymous_dynamic_method(self):
rsp = self.smugmug.albums_get(NickName='test')
self.assertEqual(rsp['method'], 'smugmug.albums.get')
示例2: get
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
def get(self):
"""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
if getattr(prefs, "category"):
self.redirect("/category/%s" % prefs.category)
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)
categories = smugmug.categories_get(NickName=prefs.nickname)
albums = smugmug.albums_get(NickName=prefs.nickname)
except Exception, e:
# Hmmm... something's not right.
self.response.out.write("There was a problem connecting to SmugMug: %s" % e)
return
示例3: TestApi
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
class TestApi(unittest.TestCase):
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.2.2', app_name='TestApp')
def test_ping(self):
rsp = self.smugmug.service_ping()
self.assertEqual(rsp['stat'], 'ok')
def test_dynamic_method(self):
self.smugmug.login_anonymously()
rsp = self.smugmug.albums_get(NickName='test')
self.assertEqual(rsp['method'], 'smugmug.albums.get')
self.smugmug.reset_auth()
def test_authorize(self):
expected = 'http://api.smugmug.com/services/oauth/authorize.mg?oauth_token=ABC&Access=Public&Permissions=Read'
self.smugmug.set_oauth_token('ABC','123')
url = self.smugmug.authorize(access='Public', perm='Read')
self.assertEqual(url, expected)
self.smugmug.reset_auth()
def test_failed_api(self):
if sys.version_info < (2, 7):
self.assertRaises(SmugMugException, lambda: self.smugmug.bad_apimethod())
else:
with self.assertRaises(SmugMugException):
self.smugmug.bad_apimethod()
示例4: SmugMug
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
#!/usr/bin/env python
from __future__ import print_function
from smugpy import SmugMug
import sys
#Aliasing for differences in Python 2.x and 3.x
if sys.version_info < (3,):
get_input = raw_input
else:
get_input = input
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXX"
OAUTH_SECRET = "YYYYYYYYYYYYYYYYYYYYYYY"
smugmug = SmugMug(api_key=API_KEY, oauth_secret=OAUTH_SECRET, app_name="TestApp")
#Oauth handshake
smugmug.auth_getRequestToken()
get_input("Authorize app at %s\n\nPress Enter when complete.\n" % (smugmug.authorize()))
smugmug.auth_getAccessToken()
albums = smugmug.albums_get(NickName="williams") # Moon River Photography, thanks Andy!
for album in albums["Albums"]:
print("%s, %s" % (album["id"], album["Title"]))
示例5: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
#.........这里部分代码省略.........
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))
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)
示例6: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
#.........这里部分代码省略.........
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:
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"):
示例7: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
#.........这里部分代码省略.........
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:
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)
示例8: SmugLine
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_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)
#.........这里部分代码省略.........
示例9: SmugMug
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
__author__ = 'hle'
from smugpy import SmugMug
if __name__ == '__main__':
API_KEY = "Ai1WhX5ErNtHYR5YFg4qFAiww6PGZs1d"
smugmug = SmugMug(api_key=API_KEY, api_version="1.3.0", app_name="TestApp")
albums = smugmug.albums_get(NickName="williams")
for album in albums["Albums"]:
print("%s, %s" % (album["id"], album["Title"]))
示例10: raw_input
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_get [as 别名]
# oauth
if TOKEN and SECRET:
smugmug.set_oauth_token(TOKEN, SECRET)
response = smugmug.auth_checkAccessToken()
#print response
else:
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']
示例11: __init__
# 需要导入模块: from smugpy import SmugMug [as 别名]
# 或者: from smugpy.SmugMug import albums_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