def import_ids_from_salesforce():
    '''Interfaces with the Salesforce database to grab the translation from
    NCES ID->SF ID for colleges and Student Number->SF ID for alumni and
    returns the translations as a tuple of two dictionarys'''
    alumni_table, college_table = aDBi.grabAccountContactTranslations()
    alumni_dict = tt.create_dict(alumni_table[1:], 0, 1)
    college_dict = tt.create_dict(college_table[1:], 0, 1)
    return (alumni_dict, college_dict)
def import_ids_from_salesforce():
    """Interfaces with the Salesforce database to grab the translation from
    NCES ID->SF ID for colleges and Student Number->SF ID for alumni and
    returns the translations as a tuple of two dictionarys"""
    alumni_table, college_table = aDBi.grabAccountContactTranslations()
    alumni_dict = tt.create_dict(alumni_table[1:], 0, 1)
    college_dict = tt.create_dict(college_table[1:], 0, 1)
    return (alumni_dict, college_dict)
def add_Salesforce_indices(combined_nsc):
    ''' Adds the Salesforce names for alumni and colleges using the student
    id "YOUR UNIQUE IDENTIFIER" from NSC and using the NCES code for college.
    Will use "N/A" for any alumnus/alumnae or college not found in the lookup'''
    # First check whether the user would prefer to add from Salesforce API
    # calls directly or via file upload
    choices = [
        'Grab directly from Salesforce',
        'Import as CSV files (see README for details)'
    ]
    response = tktools.get_buttons_answer(
        choices,
        'How would you like to get the SF IDs for alumni and colleges?')

    # Once the user responds, generate a dictionary lookup for both fields
    if response == choices[0]:  # user selected 'Grab directly from Salesforce'
        alumni_dict, college_dict = import_ids_from_salesforce()
    else:  # user wants to enter the info as a set of CSV files
        filenames = {
            'alum': [
                'alumniNames.csv',
                'Alumni names file (two columns: Your ID/SF ID)', 'r'
            ],
            'coll': [
                'collegeNames.csv',
                'College names file (two columns: NCES ID/ SF ID)', 'r'
            ]
        }
        tktools.get_filenames(filenames)
        alumni_table = tt.grab_csv_table(filenames['alum'][0])
        alumni_dict = tt.create_dict(alumni_table[1:], 0, 1)
        college_table = tt.grab_csv_table(filenames['coll'][0])
        college_dict = tt.create_dict(college_table[1:], 0, 1)

    # Now that we have a dictionary for both, generate the two new columns
    college_ids = []
    alumni_ids = []
    for row in combined_nsc.rows():
        try:
            college_ids.append(college_dict[row[combined_nsc.c('NCES ID')]])
        except:
            college_ids.append('N/A')
        try:
            alumni_ids.append(alumni_dict[row[combined_nsc.c('sId')]])
        except:
            alumni_ids.append('N/A')

    # Finally, add the new columns back to the master table
    combined_nsc.add_column('College__c', college_ids)
    combined_nsc.add_column('Student__c', alumni_ids)
def add_Salesforce_indices(combined_nsc):
    """ Adds the Salesforce names for alumni and colleges using the student
    id "YOUR UNIQUE IDENTIFIER" from NSC and using the NCES code for college.
    Will use "N/A" for any alumnus/alumnae or college not found in the lookup"""
    # First check whether the user would prefer to add from Salesforce API
    # calls directly or via file upload
    choices = ["Grab directly from Salesforce", "Import as CSV files (see README for details)"]
    response = tktools.get_buttons_answer(choices, "How would you like to get the SF IDs for alumni and colleges?")

    # Once the user responds, generate a dictionary lookup for both fields
    if response == choices[0]:  # user selected 'Grab directly from Salesforce'
        alumni_dict, college_dict = import_ids_from_salesforce()
    else:  # user wants to enter the info as a set of CSV files
        filenames = {
            "alum": ["alumniNames.csv", "Alumni names file (two columns: Your ID/SF ID)", "r"],
            "coll": ["collegeNames.csv", "College names file (two columns: NCES ID/ SF ID)", "r"],
        }
        tktools.get_filenames(filenames)
        alumni_table = tt.grab_csv_table(filenames["alum"][0])
        alumni_dict = tt.create_dict(alumni_table[1:], 0, 1)
        college_table = tt.grab_csv_table(filenames["coll"][0])
        college_dict = tt.create_dict(college_table[1:], 0, 1)

    # Now that we have a dictionary for both, generate the two new columns
    college_ids = []
    alumni_ids = []
    for row in combined_nsc.rows():
        try:
            college_ids.append(college_dict[row[combined_nsc.c("NCES ID")]])
        except:
            college_ids.append("N/A")
        try:
            alumni_ids.append(alumni_dict[row[combined_nsc.c("sId")]])
        except:
            alumni_ids.append("N/A")

    # Finally, add the new columns back to the master table
    combined_nsc.add_column("College__c", college_ids)
    combined_nsc.add_column("Student__c", alumni_ids)