def get_CSV(c_fn, a_fn, e_fn): '''This will take whatever is given, but is presumably every field in each table (so will need to be paired down''' con = tt.grab_csv_table(c_fn) acc = tt.grab_csv_table(a_fn) enr = tt.grab_csv_table(e_fn) return (con, acc, enr)
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)