This commit is contained in:
parent
6db79dae1b
commit
d9a9e77972
4 changed files with 79 additions and 57 deletions
|
@ -4,7 +4,7 @@ import urllib
|
|||
import httplib2
|
||||
|
||||
|
||||
class OpenPhoto:
|
||||
class OpenPhoto(object):
|
||||
""" Client library for OpenPhoto """
|
||||
|
||||
def __init__(self, host, consumer_key='', consumer_secret='',
|
||||
|
|
58
openphoto/main.py
Normal file
58
openphoto/main.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
import urllib
|
||||
from optparse import OptionParser
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except:
|
||||
import json
|
||||
|
||||
from openphoto import OpenPhoto
|
||||
|
||||
def main(args=sys.argv[1:]):
|
||||
consumer_key = os.getenv('consumerKey')
|
||||
consumer_secret = os.getenv('consumerSecret')
|
||||
token = os.getenv('token')
|
||||
token_secret = os.getenv('tokenSecret')
|
||||
|
||||
parser = OptionParser()
|
||||
parser.add_option('-H', '--host', action='store', type='string', dest='host',
|
||||
help="Hostname of the OpenPhoto install", default="localhost")
|
||||
parser.add_option('-X', action='store', type='choice', dest='method', choices=('GET', 'POST'),
|
||||
help="Method to use (GET or POST)", default="GET")
|
||||
parser.add_option('-F', action='append', type='string', dest='fields',
|
||||
help="Fields")
|
||||
parser.add_option('-e', action='store', type='string', dest='endpoint',
|
||||
help="Endpoint to call")
|
||||
parser.add_option('-p', action="store_true", dest="pretty", default=False)
|
||||
parser.add_option('-v', action="store_true", dest="verbose", default=False)
|
||||
parser.add_option('--encode', action="store_true", dest="encode", default=False)
|
||||
|
||||
options, args = parser.parse_args(args)
|
||||
|
||||
params = {}
|
||||
if options.fields:
|
||||
for field in options.fields:
|
||||
(key, value) = string.split(field, '=')
|
||||
params[key] = value
|
||||
|
||||
client = OpenPhoto(options.host, consumer_key, consumer_secret, token, token_secret)
|
||||
|
||||
if options.method == "GET":
|
||||
result = client.get(options.endpoint)
|
||||
else:
|
||||
result = client.post(options.endpoint)
|
||||
|
||||
if options.verbose:
|
||||
print "==========\nMethod: %s\nHost: %s\nEndpoint: %s\n==========\n\n" % (options.method, options.host, options.endpoint)
|
||||
|
||||
if options.pretty:
|
||||
print json.dumps(json.loads(result), sort_keys=True, indent=4, separators=(',',':'))
|
||||
else:
|
||||
print result
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,55 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
import urllib
|
||||
from optparse import OptionParser
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except:
|
||||
import json
|
||||
|
||||
from openphoto import OpenPhoto
|
||||
|
||||
if __name__ == "__main__":
|
||||
consumer_key = os.getenv('consumerKey')
|
||||
consumer_secret = os.getenv('consumerSecret')
|
||||
token = os.getenv('token')
|
||||
token_secret = os.getenv('tokenSecret')
|
||||
|
||||
parser = OptionParser()
|
||||
parser.add_option('-H', '--host', action='store', type='string', dest='host',
|
||||
help="Hostname of the OpenPhoto install", default="localhost")
|
||||
parser.add_option('-X', action='store', type='choice', dest='method', choices=('GET', 'POST'),
|
||||
help="Method to use (GET or POST)", default="GET")
|
||||
parser.add_option('-F', action='append', type='string', dest='fields',
|
||||
help="Fields")
|
||||
parser.add_option('-e', action='store', type='string', dest='endpoint',
|
||||
help="Endpoint to call")
|
||||
parser.add_option('-p', action="store_true", dest="pretty", default=False)
|
||||
parser.add_option('-v', action="store_true", dest="verbose", default=False)
|
||||
parser.add_option('--encode', action="store_true", dest="encode", default=False)
|
||||
|
||||
options, args = parser.parse_args(sys.argv)
|
||||
|
||||
params = {}
|
||||
if options.fields:
|
||||
for field in options.fields:
|
||||
(key, value) = string.split(field, '=')
|
||||
params[key] = value
|
||||
|
||||
client = OpenPhoto(options.host, consumer_key, consumer_secret, token, token_secret)
|
||||
|
||||
if options.method == "GET":
|
||||
result = client.get(options.endpoint)
|
||||
else:
|
||||
result = client.post(options.endpoint)
|
||||
|
||||
if options.verbose:
|
||||
print "==========\nMethod: %s\nHost: %s\nEndpoint: %s\n==========\n\n" % (options.method, options.host, options.endpoint)
|
||||
|
||||
if options.pretty:
|
||||
print json.dumps(json.loads(result), sort_keys=True, indent=4, separators=(',',':'))
|
||||
else:
|
||||
print result
|
||||
import openphoto.main
|
||||
openphoto.main.main()
|
||||
|
|
21
setup.py
21
setup.py
|
@ -1,4 +1,20 @@
|
|||
from distutils.core import setup
|
||||
requires = ['oauth2', 'httplib2']
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
requires.append('simplejson')
|
||||
|
||||
try:
|
||||
from setuptools import setup
|
||||
kw = {'entry_points':
|
||||
"""[console_scripts]\nopenphoto = openphoto.main:main\n""",
|
||||
'zip_safe': False,
|
||||
'install_requires': requires
|
||||
}
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
kw = {'scripts': ['scripts/openphoto'],
|
||||
'requires': requires}
|
||||
|
||||
setup(name='openphoto',
|
||||
version='0.1',
|
||||
|
@ -6,7 +22,6 @@ setup(name='openphoto',
|
|||
author='James Walker',
|
||||
author_email='walkah@walkah.net',
|
||||
url='https://github.com/openphoto/openphoto-python',
|
||||
requires=['oauth2'],
|
||||
packages=['openphoto'],
|
||||
scripts=['scripts/openphoto'],
|
||||
**kw
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue