luminoso_api/v5_upload.py
def _main(argv):
    """
    Handle arguments for the 'lumi-upload' command.
    """
    parser = argparse.ArgumentParser(
        description=DESCRIPTION,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument(
        '-b',
        '--base-url',
        default=URL_BASE,
        help='API root url, default: %s' % URL_BASE,
    )
    parser.add_argument(
        '-a',
        '--account-id',
        default=None,
        help='Account ID that should own the project, if not the default',
    )
    parser.add_argument(
        '-l',
        '--language',
        default='en',
        help='The language code for the language the text is in. Default: en',
    )
    parser.add_argument('-t', '--token', help="API authentication token")
    parser.add_argument(
        '-s',
        '--save-token',
        action='store_true',
        help='save --token for --base-url to ~/.luminoso/tokens.json',
    )
    parser.add_argument(
        'input_filename',
        help='The JSON-lines (.jsons) file of documents to upload',
    )
    parser.add_argument(
        'project_name',
        nargs='?',
        default=None,
        help='What the project should be called',
    )
    args = parser.parse_args(argv)
    if args.save_token:
        if not args.token:
            raise ValueError("error: no token provided")
        LuminosoClient.save_token(args.token,
                                  domain=urlparse(args.base_url).netloc)

    client = LuminosoClient.connect(url=args.base_url, token=args.token)

    name = args.project_name
    if name is None:
        name = input('Enter a name for the project: ')
        if not name:
            print('Aborting because no name was provided.')
            return

    result = upload_docs(
        client,
        args.input_filename,
        args.language,
        name,
        account=args.account_id,
        progress=True,
    )
    print(
        'Project {!r} created with {} documents'.format(
            result['project_id'], result['document_count']
        )
    )
def _main(argv):
    parser = argparse.ArgumentParser(
        description=DESCRIPTION,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument(
        '-b',
        '--base-url',
        default=URL_BASE,
        help='API root url, default: %s' % URL_BASE,
    )
    parser.add_argument(
        '-a',
        '--account-id',
        default=None,
        help='Account ID that should own the project, if not the default',
    )
    parser.add_argument(
        '-l',
        '--language',
        default='en',
        help='The language code for the language the text is in. Default: en',
    )
    parser.add_argument('-t', '--token', help="API authentication token")
    parser.add_argument(
        '-s',
        '--save-token',
        action='store_true',
        help='save --token for --base-url to ~/.luminoso/tokens.json',
    )
    parser.add_argument(
        'input_filename',
        help='The JSON-lines (.jsons) file of documents to upload',
    )
    parser.add_argument(
        'project_name',
        nargs='?',
        default=None,
        help='What the project should be called',
    )
    args = parser.parse_args(argv)
    if args.save_token:
        if not args.token:
            raise ValueError("error: no token provided")
        LuminosoClient.save_token(args.token,
                                  domain=urlparse(args.base_url).netloc)

    client = LuminosoClient.connect(url=args.base_url, token=args.token)

    name = args.project_name
    if name is None:
        name = input('Enter a name for the project: ')
        if not name:
            print('Aborting because no name was provided.')
            return

    result = upload_docs(
        client,
        args.input_filename,
        args.language,
        name,
        account=args.account_id,
        progress=True,
    )
    print(
        'Project {!r} created with {} documents'.format(
            result['project_id'], result['document_count']
        )
    )
def _main ( argv ) : parser = argparse . ArgumentParser ( description = DESCRIPTION , formatter_class = argparse . RawDescriptionHelpFormatter , ) parser . add_argument ( '-b' , '--base-url' , default = URL_BASE , help = 'API root url, default: %s' % URL_BASE , ) parser . add_argument ( '-a' , '--account-id' , default = None , help = 'Account ID that should own the project, if not the default' , ) parser . add_argument ( '-l' , '--language' , default = 'en' , help = 'The language code for the language the text is in. Default: en' , ) parser . add_argument ( '-t' , '--token' , help = "API authentication token" ) parser . add_argument ( '-s' , '--save-token' , action = 'store_true' , help = 'save --token for --base-url to ~/.luminoso/tokens.json' , ) parser . add_argument ( 'input_filename' , help = 'The JSON-lines (.jsons) file of documents to upload' , ) parser . add_argument ( 'project_name' , nargs = '?' , default = None , help = 'What the project should be called' , ) args = parser . parse_args ( argv ) if args . save_token : if not args . token : raise ValueError ( "error: no token provided" ) LuminosoClient . save_token ( args . token , domain = urlparse ( args . base_url ) . netloc ) client = LuminosoClient . connect ( url = args . base_url , token = args . token ) name = args . project_name if name is None : name = input ( 'Enter a name for the project: ' ) if not name : print ( 'Aborting because no name was provided.' ) return result = upload_docs ( client , args . input_filename , args . language , name , account = args . account_id , progress = True , ) print ( 'Project {!r} created with {} documents' . format ( result [ 'project_id' ] , result [ 'document_count' ] ) )
Handle arguments for the 'lumi-upload' command.
Handle arguments for the lumi - upload command .