本文整理汇总了Python中smugpy.SmugMug类的典型用法代码示例。如果您正苦于以下问题:Python SmugMug类的具体用法?Python SmugMug怎么用?Python SmugMug使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmugMug类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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()
示例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')
示例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=')
示例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
示例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
示例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'];
示例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')
示例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 = {}
示例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
示例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 = {}
示例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')
示例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"])
示例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
示例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