Exemplo n.º 1
0
		print image.filename + " - " + image.caption

def print_node(node, indent):
	do_indent(indent)
	stdout.write("'" + node.name + "' (" + node.type + ") - " + node.privacy)
	if node.type == "Album":
		print_album(node, indent)
	print
	children=node.get_children(connection)
	for child in children:
		print_node(child, indent+1)

if not api_key or not api_secret:
  raise Exception('API key and secret are required. see test_setup.py')

connection = Connection(api_key, api_secret, user_agent="Test user agent/2.4")

if not token or not secret:
	auth_url = connection.get_auth_url(access="Full", permissions="Modify")

	print "Visit the following URL and retrieve a verification code:%s%s" % (linesep, auth_url)

	stdout.write('Enter the six-digit code: ')
	stdout.flush()
	verifier = stdin.readline().strip()

	at, ats = connection.get_access_token(verifier)

	print "Token: " + at
	print "Secret: " + ats
Exemplo n.º 2
0
def print_node(node, indent):
    do_indent(indent)
    stdout.write("'" + node.name + "' (" + node.type + ") - " + node.privacy)
    if node.type == "Album":
        print_album(node, indent)
    print
    children = node.get_children(connection)
    for child in children:
        print_node(child, indent + 1)


if not api_key or not api_secret:
    raise Exception('API key and secret are required. see test_setup.py')

connection = Connection(api_key, api_secret, user_agent="Test user agent/2.4")

if not token or not secret:
    auth_url = connection.get_auth_url(access="Full", permissions="Modify")

    print "Visit the following URL and retrieve a verification code:%s%s" % (
        linesep, auth_url)

    stdout.write('Enter the six-digit code: ')
    stdout.flush()
    verifier = stdin.readline().strip()

    at, ats = connection.get_access_token(verifier)

    print "Token: " + at
    print "Secret: " + ats
Exemplo n.º 3
0
def main():
    global root_node
    global root_dir

    parser = ArgumentParser()
    parser.add_argument("site", help="the site to upload to")
    parser.add_argument("path", help="the path containing local photos")
    parser.add_argument("-r",
                        "--reauth",
                        help="force reauthorisation",
                        action="store_true")
    parser.add_argument("-k", "--api-key", help="smugmug API key")
    parser.add_argument("-s", "--api-secret", help="smugmug API secret")
    args = parser.parse_args()

    root_dir = args.path

    config = Config()
    site_config = {}

    if ("api-key" not in config.json and not args.api_key) or \
     ("api-secret" not in config.json and not args.api_secret):
        print "API key and secret must be in either config or on command line"

        parser.print_help()
        exit(-1)

    if args.site in config.json:
        site_config = config.json[args.site]

    save_config = False

    if args.api_key:
        config.json["api-key"] = args.api_key
        save_config = True

    if args.api_secret:
        config.json["api-secret"] = args.api_secret
        save_config = True

    if "exclusions" not in site_config:
        save_config = True
        site_config["exclusions"] = []

    connection = Connection(config.json["api-key"],
                            config.json["api-secret"],
                            user_agent="pysmugmugsync/" +
                            get_distribution('pysmugmugsync').version)

    if args.reauth or "token" not in site_config or "secret" not in site_config:
        auth_url = connection.get_auth_url(access="Full", permissions="Modify")

        print "Visit the following URL and retrieve a verification code:%s%s" % (
            linesep, auth_url)

        stdout.write('Enter the six-digit code: ')
        stdout.flush()
        verifier = stdin.readline().strip()

        at, ats = connection.get_access_token(verifier)

        site_config["token"] = at
        site_config["secret"] = ats
        save_config = True

    if save_config:
        config.json[args.site] = site_config
        config.write()

    connection.authorise_connection(site_config["token"],
                                    site_config["secret"])
    user = User.get_authorized_user(connection)
    print "User: "******" (" + user.name + ")"
    root_node = Node.get_node(connection, user.node)

    root = SmugMugLocalAlbum(exclusions=site_config["exclusions"],
                             directory=args.path)

    sync_node(connection, root, root_node)