bluethundr12

Untitled

Jul 16th, 2020
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. def set_db():
  2.     myclient = connect_db()
  3.     message = "Select Database"
  4.     banner(message)
  5.     today = datetime.today()
  6.     today = today.strftime("%m-%d-%Y")
  7.     if __name__ == '__main__':
  8.         print(Fore.CYAN + "Available MongoDB Databases:")
  9.         if myclient != None:
  10.             # the list_database_names() method returns a list of strings
  11.             database_names = myclient.list_database_names()
  12.             counter = 1
  13.             for db in database_names:
  14.                 message = str(counter) + '. ' + db
  15.                 print(message)
  16.                 counter = counter + 1
  17.         print ("There are", len(database_names), "databases.\n")
  18.         print(f"Please select a database. Enter a number 1 through {len(database_names)}.")
  19.         choice = input("Enter a number: ")
  20.         if is_digit(choice) == True:
  21.             if int(choice) > counter:
  22.                 print("Wrong selection.")
  23.                 set_db()
  24.             choice = int(choice)
  25.             choice = choice - 1
  26.             mydb = database_names[choice]
  27.             #mydb = myclient['aws_ec2_list']
  28.             print(f"You've selected: {mydb}\n")
  29.         else:
  30.             print("Must enter a digit. Try again.\n")
  31.             set_db()
  32.     else:
  33.         mydb = myclient['aws_ec2_list']
  34.     instance_col = 'ec2_list-' + today
  35.     instance_col = mydb[instance_col]
  36.     return mydb, instance_col
Advertisement
Add Comment
Please, Sign In to add comment