'''This is a public script using sortedcontainers.
A dictioniary is created which allows for user input to print/add/remove/lookup users'''
from sortedcontainers import SortedDict
import sys
#adding a comment here

def print_menu():
    print('1. Print Users')
    print('2. Add a User')
    print('3. Remove a User')
    print('4. Lookup a Username')
    print('5. Quit')
    print()


# Create dictionary with key = Names, value = user_name
usernames = SortedDict()
usernames['Summer'] = 'summerela'
usernames['William'] = 'GoofyFish'
usernames['Steven'] = 'LoLCat'
usernames['Zara'] = 'zanyZara'
usernames['Renato'] = 'songDude'

# setup counter to store menu choice
menu_choice = 0

# display your menu
print_menu()

# as long as the menu choice isn't "quit" get user options
# if an invalid menu choice is added, exception handling will notify user that only numbers are acceptable for options
while menu_choice != 5:
    #exception handling
    try:# get menu choice from user
        menu_choice = int(input("Type in a number (1-5): "))
    except ValueError:
        print("Numbers Only")
        sys.exit()
    # view current entries
    if menu_choice == 1:
        print("Current Users:")
        for x, y in usernames.items():
            print("Name: {} \tUser Name: {} \n".format(x, y))

    # add an entry
    elif menu_choice == 2:
        print("Add User")
        name = input("Name: ")
        username = input("User Name: ")
        usernames[name] = username

    # remove an entry
    elif menu_choice == 3:
        print("Remove User")
        name = input("Name: ")
        if name in usernames:
            usernames.pop(name)

    # view user name
    elif menu_choice == 4:
        print("Lookup User")
        name = input("Name: ")
        if name in usernames:
            print("Their username is: {}".format(usernames[name])) # print the username
        else:
            print ("username not found")

    # is user enters something strange, show them the menu
    elif menu_choice != 5:
        print_menu()
