bluethundr12

Untitled

Jul 15th, 2020
1,097
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def set_db():
  2.     myclient = connect_db()
  3.     today = datetime.today()
  4.     today = today.strftime("%m-%d-%Y")
  5.     if __name__ == '__main__':
  6.         message = "Select Database"
  7.         banner(message)
  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[choice]
  28.             print(f"You've selected: {mydb}\n")
  29.         else:
  30.             print("Must enter a digit. Try again.\n")
  31.             set_db()
  32.         ## Run as a stand alone script
  33.         instance_col = 'ec2_list-' + today
  34.         print(f"***Instance col type: {type(instance_col)}***")
  35.         instance_col = mydb[instance_col]
  36.         print(f"Type MYDB: {mydb}")
  37.         time.sleep(10)
  38.     else:
  39.         # Called from
  40.         mydb = myclient['aws_ec2_list']
  41.         print(f"Type MYDB: {mydb}")
  42.         time.sleep(10)
  43.         instance_col = 'ec2_list-' + today
  44.         print(f"***Instance col type: {type(instance_col)}***")
  45.         time.sleep(30)
  46.         instance_col = mydb[instance_col]
  47.     return mydb, instance_col
RAW Paste Data