Esempio n. 1
0
def basic_search(query):
    """ Function for initializing a search for an orcid id.

    Parameters
    ----------
    :param query: string
        Query built from user input.

    Returns
    -------
    :returns: no return.
    """

    # Initialize and populate all variables and dictionaries
    search_obj = OrcidSearchResults(sandbox)
    search_obj.basic_search(query)
    actual_total = search_obj.actual_total_results
    total_results = search_obj.total_results
    # orcid_id = search_obj.orcid_id

    # Print results
    search_obj.print_basic()

    # Print total results if actual results are above 100
    if total_results < actual_total:
        print 'Actual Total Results: {}'.format(actual_total)
        print('')

    # Ask user if they would like to search again.
    while True:
        new_instance = click.prompt('Would you like to search again [y/N]?', default='N', show_default=False)
        print('')

        if new_instance in ('y', 'Y', 'yes', 'YES', 'Yes'):
            search_type(args = ['-b'])
            break
        elif new_instance in ('n', 'N', 'no', 'NO', 'No'):
            exit(1)
        else:
            print('You did not pick an appropriate answer.')
Esempio n. 2
0
def basic_search_config(query):
    """ Function for initializing a search for an orcid id, and then creates a RDF
        configuration file automatically.

    Parameters
    ----------
    :param query: string
        Query built from user input.

    Returns
    -------
    :returns: no return.
    """

    # Initialize and populate all variables and dictionaries
    search_obj = OrcidSearchResults(sandbox)
    search_obj.basic_search(query)
    actual_total = search_obj.actual_total_results
    total_results = search_obj.total_results
    # orcid_id = search_obj.orcid_id

    # Print results
    search_obj.print_basic_alt()

    # Print total results if actual results are above 100
    if total_results < actual_total:
        print 'Actual Total Results: {}'.format(actual_total)
        print('')

    # Get list of Orcid ID's from results
    id_list = search_obj.orcid_id

    # Write config if only one result was found
    if total_results == 1:
        orcid_id = id_list[0]
        config = ConfigManager(orcid_id=orcid_id, sandbox=sandbox)
        config.write_config()

    # If no results are found
    elif total_results == 0:
        print("No results where found. Please try again.\n")
        search_type(args = ['-c'])

    # Allow user to select Orcid profile if multiple results are found
    else:
        id_dict = dict()
        # Get list of Orcid ID's and correspond count with ID
        for i, id in enumerate(id_list):
            id_dict[i + 1] = id

        selected = None
        while not selected:
            try:
                selected = click.prompt('Select the result # of the record (Type "N" for another search, "Exit" to abort)')
                print("")
                orcid_id = id_dict[int(selected)]
                config = ConfigManager(orcid_id=orcid_id, sandbox=sandbox)
                config.write_config()
            except (KeyError):
                print('That is not a valid selection.  Please try again.\n')
                selected = None
            except (ValueError):
                if selected in ('N', 'n'):
                    search_type(args = ['-c'])
                elif selected in ('exit', 'Exit', 'EXIT'):
                    exit()
                else:
                    print('That is not a valid selection.  Please try again.\n')
                    selected = None