本文整理汇总了Python中smugpy.SmugMug类的典型用法代码示例。如果您正苦于以下问题:Python SmugMug类的具体用法?Python SmugMug怎么用?Python SmugMug使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmugMug类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
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
开发者ID:scottwallacesh,项目名称:smughost,代码行数:27,代码来源:main.py
示例2: TestApiImageUploadOauth
class TestApiImageUploadOauth(unittest.TestCase):
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp', oauth_secret=OAUTH_SECRET)
def test_image_upload_oauth(self):
self.smugmug.set_oauth_token('ABC','123')
rsp = self.smugmug.images_upload(File='tests/smuggy.jpg', AlbumID=1234)
self.assertEqual(rsp['method'], 'smugmug.images.upload')
self.smugmug.reset_auth()
开发者ID:Ramblurr,项目名称:smugpy,代码行数:9,代码来源:test_api.py
示例3: _smugmugOauthRequestToken
def _smugmugOauthRequestToken(self, access="Public", perm="Read"):
smugmug = SmugMug(api_key=self.api_key, oauth_secret=self.oauth_secret, app_name=self.app_name)
# Get a token that is short-lived (probably about 5 minutes) and can be used
# only to setup authorization at SmugMug
response = smugmug.auth_getRequestToken()
# Get the URL that the user must visit to authorize this app (implicilty includes the request token in the URL)
url = smugmug.authorize(access=access, perm=perm)
return url, response['Auth'] # (should contain a 'Token')
开发者ID:huynle,项目名称:smugphoto,代码行数:10,代码来源:auth.py
示例4: TestOauth
class TestOauth(unittest.TestCase):
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp', oauth_secret=OAUTH_SECRET)
def test_get_request_token(self):
self.smugmug.auth_getRequestToken()
self.assertNotEqual(self.smugmug.oauth_token, None)
self.assertNotEqual(self.smugmug.oauth_token_secret, None)
self.smugmug.reset_auth()
def test_get_access_token(self):
self.smugmug.auth_getAccessToken()
self.assertNotEqual(self.smugmug.oauth_token, None)
self.assertNotEqual(self.smugmug.oauth_token_secret, None)
self.smugmug.reset_auth()
def test_request_signature(self):
url = 'http://api.smugmug.com/services/api/json/'
parameters = dict(
method = 'smugmug.albums.get',
NickName = 'williams'
)
timestamp = 1341423551
nonce = 'b7cdabcabc3c4f7f91508da3bca9798f'
signed_args = self.smugmug._get_oauth_request_params(url=url, parameters=parameters, method='POST', timestamp=timestamp, nonce=nonce)
self.assertEqual(signed_args['oauth_signature'], 'f++GOXf9BhSVhGy1dxGSbmaA0ng=')
开发者ID:chrishoffman,项目名称:smugpy,代码行数:26,代码来源:test_oauth.py
示例5: smug_init
def smug_init():
smugmug = SmugMug(api_key=settings['smugmug']['api_key'],\
oauth_secret=settings['smugmug']['oauth_secret'],\
app_name=settings['smugmug']['app'])
oauth_token_id = settings['smugmug']['oauth_token_id']
oauth_token_secret = settings['smugmug']['oauth_token_secret']
smugmug.set_oauth_token(oauth_token_id, oauth_token_secret)
return smugmug
开发者ID:ethan-c-,项目名称:slideshow,代码行数:11,代码来源:get_IDs.py
示例6: login
def login(verbose):
if verbose:
print "LOGGING IN..."
smugmug = SmugMug(api_key=login_info.API_KEY, api_version="1.2.2",
app_name="CrimsonStore")
smugmug.login_withPassword(EmailAddress=login_info.USER_NAME,
Password=login_info.PASSWORD)
if verbose:
print "LOGGED IN\n"
return smugmug
开发者ID:BharadwajMulakala,项目名称:crimsonstore,代码行数:13,代码来源:smug_lib.py
示例7: smugmugOauthGetAccessToken
def smugmugOauthGetAccessToken(requestToken):
# Use the request token to log in (which should be authorized now)
smugmug = SmugMug(api_key=API_KEY, oauth_secret=OAUTH_SECRET,
oauth_token=requestToken['Token']['id'],
oauth_token_secret=requestToken['Token']['Secret'],
app_name=APP_NAME)
# The request token is good for 1 operation: to get an access token.
response = smugmug.auth_getRequestToken()
# The access token should be good until the user explicitly
# disables it at smugmug.com in their settings panel.
return response['Auth'];
开发者ID:rootbeer,项目名称:smugpy,代码行数:13,代码来源:example-oauth.py
示例8: TestApi130
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')
开发者ID:Ramblurr,项目名称:smugpy,代码行数:7,代码来源:test_api.py
示例9: __init__
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 = {}
开发者ID:ds20,项目名称:smugline,代码行数:7,代码来源:smugline.py
示例10: smug_auth
def smug_auth():
smugmug = SmugMug(api_key=config.get('smugmug', 'key'), oauth_secret=config.get('smugmug', 'secret'), api_version="1.3.0", app_name="flickr-to-smugmug")
if config.has_option('smugmug', 'oauth_token'):
smugmug.set_oauth_token(config.get('smugmug', 'oauth_token'), config.get('smugmug', 'oauth_token_secret'))
else:
smugmug.auth_getRequestToken()
get_input("Authorize app at %s\n\nPress Enter when complete.\n" % (smugmug.authorize(access='Full', perm='Modify')))
smugmug.auth_getAccessToken()
config.set('smugmug', 'oauth_token', smugmug.oauth_token)
config.set('smugmug', 'oauth_token_secret', smugmug.oauth_token_secret)
save()
return smugmug
开发者ID:Ramblurr,项目名称:smugtools,代码行数:12,代码来源:common.py
示例11: __init__
def __init__(self, api_key=None, email=None, password=None):
if api_key is None:
self.api_key = os.environ.get('SMUGMUG_API', None)
else:
self.api_key = api_key
self.email = email
self.password = password
self.smugmug = SmugMug(
api_key=self.api_key,
api_version="1.2.2",
app_name="SmugLine")
self.login()
self.md5_sums = {}
开发者ID:subutai,项目名称:smugline,代码行数:13,代码来源:smugline.py
示例12: TestLogin130
class TestLogin130(unittest.TestCase):
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp')
def test_login_anonymously(self):
if sys.version_info < (2, 7):
self.assertRaises(SmugMugException, lambda: self.smugmug.login_anonymously())
else:
with self.assertRaises(SmugMugException):
self.smugmug.login_anonymously()
def test_login_withHash(self):
if sys.version_info < (2, 7):
self.assertRaises(SmugMugException, lambda: self.smugmug.login_withHash(UserID='test', PasswordHash='ABCDE'))
else:
with self.assertRaises(SmugMugException):
self.smugmug.login_withHash(UserID='test', PasswordHash='ABCDE')
def test_login_withPassword(self):
if sys.version_info < (2, 7):
self.assertRaises(SmugMugException, lambda: self.smugmug.login_withPassword(EmailAddress='[email protected]', Password='ABC123'))
else:
with self.assertRaises(SmugMugException):
self.smugmug.login_withPassword(EmailAddress='[email protected]', Password='ABC123')
开发者ID:Ramblurr,项目名称:smugpy,代码行数:24,代码来源:test_login.py
示例13: SmugMug
#!/usr/bin/env python
from smugpy import SmugMug
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXX"
smugmug = SmugMug(api_key=API_KEY, app_name="TestApp")
smugmug.login_anonymously()
albums = smugmug.albums_get(NickName="williams") # Moon River Photography, thanks Andy!
for album in albums["Albums"]:
print "%s, %s" % (album["id"], album["Title"])
开发者ID:ivarvong,项目名称:smugpy,代码行数:12,代码来源:example-anonymous.py
示例14: __init__
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
开发者ID:dyon,项目名称:TwiMug,代码行数:5,代码来源:SmugMugClient.py
示例15: docopt
SCRIPTPATH = os.path.dirname(os.path.abspath(__file__))
# parse command line arguments
arguments = docopt(__doc__, version='smugmuglinkgen.py 0.1')
# parse config file
config = configparser.ConfigParser()
config.read(SCRIPTPATH+'/smugmuglinkgen.conf')
API_KEY = config.get('main', 'api_key')
API_SECRET = config.get('main', 'api_secret')
TOKEN = config.get('main', 'token')
SECRET = config.get('main', 'secret')
USERNAME = config.get('main', 'smugmug_user')
# set up smugmug API
smugmug = SmugMug(api_key=API_KEY, oauth_secret=API_SECRET, app_name="get_gallery_links")
# 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
开发者ID:stacybrock,项目名称:smugmuglinkgen,代码行数:31,代码来源:smugmuglinkgen.py
示例16: SmugLine
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,代码行数:101,代码来源:smugline.py
示例17: setUp
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp', oauth_secret=OAUTH_SECRET)
开发者ID:chrishoffman,项目名称:smugpy,代码行数:2,代码来源:test_oauth.py
示例18: SmugMug
__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"]))
开发者ID:huynle,项目名称:smugphoto,代码行数:13,代码来源:main.py
示例19: SmugLine
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,代码行数:101,代码来源:smugline.py
示例20: setUp
def setUp(self):
self.smugmug = SmugMug(api_key=API_KEY, api_version='1.2.2', app_name='TestApp')
开发者ID:Ramblurr,项目名称:smugpy,代码行数:2,代码来源:test_api.py
注:本文中的smugpy.SmugMug类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论