Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_db():
- myclient = connect_db()
- today = datetime.today()
- today = today.strftime("%m-%d-%Y")
- if __name__ == '__main__':
- message = "Select Database"
- banner(message)
- print(Fore.CYAN + "Available MongoDB Databases:")
- if myclient != None:
- # the list_database_names() method returns a list of strings
- database_names = myclient.list_database_names()
- counter = 1
- for db in database_names:
- message = str(counter) + '. ' + db
- print(message)
- counter = counter + 1
- print ("There are", len(database_names), "databases.\n")
- print(f"Please select a database. Enter a number 1 through {len(database_names)}.")
- choice = input("Enter a number: ")
- if is_digit(choice) == True:
- if int(choice) > counter:
- print("Wrong selection.")
- set_db()
- choice = int(choice)
- choice = choice - 1
- #mydb = database_names[choice]
- mydb = myclient[choice]
- print(f"You've selected: {mydb}\n")
- else:
- print("Must enter a digit. Try again.\n")
- set_db()
- ## Run as a stand alone script
- instance_col = 'ec2_list-' + today
- print(f"***Instance col type: {type(instance_col)}***")
- instance_col = mydb[instance_col]
- print(f"Type MYDB: {mydb}")
- time.sleep(10)
- else:
- # Called from
- mydb = myclient['aws_ec2_list']
- print(f"Type MYDB: {mydb}")
- time.sleep(10)
- instance_col = 'ec2_list-' + today
- print(f"***Instance col type: {type(instance_col)}***")
- time.sleep(30)
- instance_col = mydb[instance_col]
- return mydb, instance_col
RAW Paste Data