def write_csv(file_contents_imported, fields, Write_on_exit, LFS): stop = False number_of_lines = 0 # While stop is not equal to true or while not stop. for _ in file_contents_imported: number_of_lines += 1 while not stop: field_line = [] for each in fields: number_of_lines += 1 Field_answer = Interaction_Lib.Prompt_feedback( f'What would you like to put under {each}?', False) field_line.append(Field_answer) is_empty = file_contents_imported.get(number_of_lines, 'Empty') if is_empty == 'Empty': field_line = get_line_string(field_line, LFS) print(field_line) file_contents_imported[number_of_lines] = field_line else: print('Error, line taken Please try again') exit_loop = Interaction_Lib.Prompt_feedback("stop writing?", True) # will stop loop if you type yes in there if "yes" in exit_loop: print("Stopping") # Use if you want to mimic the old behavior of the function, NOTE; much slower due to how this handles # writing compared to the old one, I recommend waiting until you save to write these changes if Write_on_exit: write_back_to_csv(file_contents_imported, "Text_modified.csv", LFS) stop = True return file_contents_imported
def make_csv_header(file_params): # Enter the amount you want number_of_params = Interaction_Lib.Prompt_feedback( "How many Parameters do you need?", True) number_of_params = int(number_of_params) # Repeat for the amount of times specified for x in range(0, number_of_params): # Appends to file_params while letting the user know which parameter it is. file_params.append( Interaction_Lib.Prompt_feedback(f"Parameter number {x}", False)) return file_params
def delete_csv_header(file_params): file_parameters_temp = file_params param_to_delete = Interaction_Lib.Prompt_feedback( 'Please enter Parameter to remove.', False) file_parameters_temp.remove(param_to_delete) file_params = file_parameters_temp Prompt = Interaction_Lib.Prompt_feedback( 'Would you like to delete another?', True) if 'yes' in Prompt: delete_csv_header(file_params) elif 'y' in Prompt: delete_csv_header(file_params) else: return file_params
def delete_one_line(file_contents_imported, line): if line != 1: del file_contents_imported[line] else: answer = Interaction_Lib.Prompt_feedback( 'Are you sure you would like to delete your header? You cannot' 'modify the CSV properly without it!', True) if 'yes' in answer: del file_contents_imported[line]
def modify(Parameter, line_to_modify, file_contents_imported, Write_on_exit, LFS): file_params = retrieve_line_list(file_contents_imported, 1, LFS) column = header_to_column(file_params, Parameter, False) old_line = retrieve_line_list(file_contents_imported, column, LFS) old_line[column] = Interaction_Lib.Prompt_feedback( f'What would you like to replace in {Parameter} on line {line_to_modify}. current value: ' f'{file_contents_imported[line_to_modify][column]}', False) print(old_line) file_contents_imported[line_to_modify] = old_line if Write_on_exit: write_back_to_csv(file_contents_imported, "Text_modified.csv", LFS=LFS)
def get_csv_header(file_contents_imported): # Sets this to file_contents_imported and gets the first one since it is where the file starts not zero this is # done to match Text editors and also allows me to slip in these params .get allows me to get a 'none' response # if it equals none file_params = retrieve_line_list(file_contents_imported, 1, "none") Answer = "yes" # Interaction_Lib.Prompt_feedback(f'Does {file_params} sound correct?', True) if file_params == "none": # run make params file_params = make_csv_header(file_params) elif 'yes' not in Answer: print(Answer) prompt_input = Interaction_Lib.Prompt_feedback( 'Do you need to create or delete Parameters?', True) if 'delete' in prompt_input: file_params = delete_csv_header(file_params) if 'create' in prompt_input: file_params = make_csv_header(file_params) file_contents_imported[1] = file_params return file_params
def search_csv(file_contents_imported): # Grabs the input to search for term = Interaction_Lib.Prompt_feedback('Search term', False) if term == 'exit:': return 1 # Goes through the list searches = 0 for line in file_contents_imported: try: # Checks if the term is in the line_number line_contents = file_contents_imported[line] # if the term is in line_contents if term in line_contents: # If it is Prints the line_number and contents print(f'Row# {line}, {line_contents}') # increment searches searches = +1 except TypeError: pass # If there are no searches recorded print no hits found if searches == 0: print('No Hits found!')
def shell_prompt(): Interaction_Lib.End_User_prompt(Index_of_commands)
def message_prompt(Text, Desensitize): Interaction_Lib.Prompt_feedback(Text, Desensitize=Desensitize)