def save_qualifying_loans(qualifying_loans): """Saves the qualifying loans to a CSV file. Args: qualifying_loans (list of lists): The qualifying bank loans. """ # Provide the user the choice to save to .csv file. user_option = questionary.text( "Want to save qualifying_loans(.csv): enter 'Yes' or 'No'").ask() # Removing space and normalizing data input to lower case. user_option = " ".join(user_option.split()).lower() # Testing an if statment based on user input. if user_option == 'yes': # Questioning user and storing answer to a variable. csvpath = questionary.text( "Enter a file path to save './data/output/qualifying_loans.csv':" ).ask() # Removing space and normalizing data input to lower case. csvpath = csvpath.replace(" ", "").lower() csvpath = Path(csvpath) # Validates input file qualifying_loans.csv location. if not csvpath.exists(): sys.exit(f"Oops! Can't find this path: {csvpath}") else: save_csv(csvpath, qualifying_loans) else: # User doesn't enter Yes, so the app exists. sys.exit( f"You have opt out of saving file. Thank you for using this app.")
def test_save_csv(): # @TODO: Your code here! # Use Path from pathlib to output the test csv to ./data/output/qualifying_loans.csv qualifying_loans = "test" csvpath = Path("./data/output/save_file.csv") save_csv(qualifying_loans) assert csvpath.exists()
def run(): """The main function for running the script.""" # Load the latest Bank data bank_data = load_bank_data() # Get the applicant's information credit_score, debt, income, loan_amount, home_value = get_applicant_info() # Find qualifying loans qualifying_loans = find_qualifying_loans(bank_data, credit_score, debt, income, loan_amount, home_value) # Save qualifying loans csvoutpath = save_qualifying_loans(qualifying_loans) save_csv(csvoutpath, qualifying_loans)
def test_save_csv(): qualifying_loans = "test" csvoutpath = Path("./tests/data/output/qualifying_loans.csv") fileio.save_csv( csvoutpath, qualifying_loans, [ # Headers for outputted csv file "lender", "max_loan_amount", "max_loan_to_value", "max_debt_to_income", "min_credit_score", "interest_rate", ], ) assert csvoutpath.exists()
def save_qualifying_loans(qualifying_loans): """Saves the qualifying loans to a CSV file. Args: qualifying_loans (list of lists): The qualifying bank loans. """ # Complete the usability dialog for savings the CSV Files. csvpath = Path('./data/qualifying_loans.csv') save_csv(csvpath, qualifying_loans) answer = questionary.text( "Would you like to save this list of qualifying loans?").ask() message = "Thank you, best of luck!" if answer == 'yes': message = questionary.text("Enter output file path:").ask() save_csv(Path(message), qualifying_loans) print(message)
def save_qualifying_loans(qualifying_loans): """Saves the qualifying loans to a CSV file. Args: qualifying_loans (list of lists): The qualifying bank loans. """ # @TODO: Complete the usability dialog for savings the CSV Files. # YOUR CODE HERE! #Prompt user with choice to save data and file path to save the csv #Otherwise, exit the program choice = questionary.confirm("Would you like to save a list of the qualifying loans?").ask() if choice: output_path = questionary.text("Enter a file path to save the data (.csv):").ask() if not choice: sys.exit("Program terminated") print ("End program") header = ["Lender","Max Loan Amount","Max LTV","Max DTI","Min Credit Score","Interest Rate"] save_csv(output_path,qualifying_loans)
def save_qualifying_loans(qualifying_loans): """Saves the qualifying loans to a CSV file. Args: qualifying_loans (list of lists): The qualifying bank loans. """ # prompts dialog asking confirming if the user wants to save the csv file save_status = questionary.confirm("Do you want save this csv file").ask() """Prompt dialog to enter path Returns: Saves the qualifying loans to a csv file """ if save_status == True: csvpath = questionary.text("enter path").ask() save_csv(csvpath, qualifying_loans) # if user does not want to save file, displays message: Thank you for using the Loan Qualifier App! and user exits the program if save_status == False: sys.exit(f"Thank you for using the Loan Qualifier App!")
def save_qualifying_loans(qualifying_loans): """Saves the qualifying loans to a CSV file. Args: qualifying_loans (list of lists): The qualifying bank loans. """ # @TODO: Complete the usability dialog for saving the CSV Files. # YOUR CODE HERE! #Setting a condition where if the user does not qualify for any loans, the app will print a message and exit the app if qualifying_loans == []: sys.exit( "You have no qualifying loans at this time. Please try again at another time. Thank you." ) #Using Quesionary confirm() to get user input of whether they want to save their CSV file or not else: confirm_save = questionary.confirm( "Would you like to save your file? Type 'y' for Yes or 'n' for No." ).ask() if confirm_save == True: csvoutpath = questionary.text( "Enter a file path of where you would like to save your file." ).ask() csvoutpath = Path(csvoutpath) print( f"Your file has been saved in {csvoutpath}. Thank you for using our app!" ) #Deleted save_csv from run(), and calling it here to save the file from user's input return save_csv(qualifying_loans) else: sys.exit( "Your file has not been saved. Thank you for using our app!")
def test_save_csv(): csvpath = Path('../data/qualifying_loans.csv') bank_data = [] header = [] fileio.save_csv(csvpath, bank_data, header) assert csvpath.exists() == True