bluethundr12

Untitled

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