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)
arg_dict['out'] = [args.out, out_help, 'w'] if not args.db: if args.csv: args.db = False else: args.db = tktools.get_yes_no( 'Get database info directly from Salesforce?') if not args.out and not args.db: arg_dict['enr'] = [args.enr, enr_help, 'r'] arg_dict['con'] = [args.con, con_help, 'r'] arg_dict['acc'] = [args.acc, acc_help, 'r'] if arg_dict: tktools.get_filenames(arg_dict) if 'con' in arg_dict: args.con = arg_dict['con'][0] if 'acc' in arg_dict: args.acc = arg_dict['acc'][0] if 'enr' in arg_dict: args.enr = arg_dict['enr'][0] if 'out' in arg_dict: args.out = arg_dict['out'][0] if args.summary: by_hs = False else: by_hs = True if args.db: infiles = None else: infiles = (args.con, args.acc, args.enr) main(infiles,args.out,args.hs, by_hs, args.verbose)