Exemple #1
0
def RunApp():
    user_input_main = menu_functions.main_menu()
    while user_input_main != "0":
        
        if user_input_main == "1":
            user_input_product = menu_functions.product_menu()
            
            while user_input_product != 5:
                
                if user_input_product == "1":
                    print_functions.print_list(products)
                    
                elif user_input_product == "2":
                    new_product_name = input("What product would you like to add? (Press 0 to cancel!) ")
                    new_price = float(input("What is the price of this product?"))
                    new_product_index = max([int(product["index"])for product in products]) + 1
                    if new_product_name == "0":
                        menu_functions.product_menu()
                    
                    new_product = {
                        "index": new_product_index, 
                        "name": new_product_name,
                        "price": new_price}
                    
                    update_functions.add_dict_to_list(new_product, products)
                    save_functions.save_dict_products_to_csv("products.csv", products)
                elif user_input_product == "3":
                    product_name = input("What product would you like to update? (Press 0 to cancel!)")
                    while True:
                        for product in products:
                            updated_product_name = input("Please enter the updated Product name")
                            if updated_product_name != "":
                                product['name'] = updated_product_name
                            updated_product_price = float(input("What is the updated price of this product?"))
                            if updated_product_price != "":
                                product['price'] = updated_product_price
                                break
                elif user_input_product == "4":
                    delete_product = input("What product would you like to delete? (Press 0 to cancel!)")
                    
                    for product in products:
                        
                        if product['name'] == delete_product:
                        
                            update_functions.delete_dict_in_list(product, products)
                            
                    if delete_product == "0":
                        menu_functions.product_menu()
                    
                elif user_input_product == "5":
                    
                    break
                else:
                    print("Bye Bye")
                    sys.exit()
                user_input_product = menu_functions.product_menu() 
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "2":
            user_input_courier = menu_functions.courier_menu()
            
            while user_input_courier != 5:
                
                if user_input_courier == "1":
                    print_functions.print_list(couriers)
                    
                elif user_input_courier == "2":
                    new_courier_name = input("Which courier would you like to add? (Press 0 to cancel!)")
                    new_courier_phone = int(input("What is the contact number of the courier?"))
                    new_courier_index = max([int(courier["index"])for courier in couriers]) + 1
                    new_courier = {
                        "index": new_courier_index,
                        "name": new_courier_name,
                        "phone": new_courier_phone}
                    
                    update_functions.add_dict_to_list(new_courier, couriers)
                    save_functions.save_dict_couriers_to_csv("couriers.csv", couriers)
                    
                    if new_courier_name == "0":
                        menu_functions.courier_menu()
                    
                elif user_input_courier == "3":
                    courier_name = input("Which courier would you like to delete? (Press 0 to cancel!)")
                    
                    for courier in couriers:
                        
                        if courier['name'] == courier_name:
                            update_functions.delete_dict_in_list(courier, couriers)
                        if courier == "0":
                            menu_functions.courier_menu()
                    update_functions.delete_item_in_list(courier_name, couriers)
                    
                elif user_input_courier == "4":
                    courier_name = input("Which courier details would you like to update? (Press 0 to cancel!)")
                    
                    for courier in couriers:
                        
                        if courier['name'] == courier_name:
                            while True:
                                new_courier_name = input("Please enter the updated courier's name")
                                if new_courier_name != "":
                                    courier['name'] = new_courier_name
                                new_courier_phone = input("Please enter the updated phone number of the courier")
                                if new_courier_phone != "":
                                    courier['phone'] = new_courier_phone
                                    
                                break
                elif user_input_courier == "5":
                    break
                user_input_courier = menu_functions.courier_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "3":
            user_input_order = menu_functions.order_menu()
            
            while user_input_order != 6:
                
                if user_input_order == "1":
                    print_functions.print_list(orders)
                    
                elif user_input_order == "2":
                    new_order_name = input("Please enter the name of the customer: ")
                    new_order_phone = input("Please enter the phone number of the customer: ")
                    new_order_address = input("Please enter the address of the customer: ")
                    print("The available couriers are::")
                    new_order = {
                        "customer_name": new_order_name,
                        "customer_phone": new_order_phone,
                        "customer_address": new_order_address,
                        "courier": text_functions.courier_list_select()["index"],
                        "status": "Preparing",
                        "items": text_functions.product_list_select()["index"]
                        }
                        
                        
                    update_functions.add_dict_to_list(new_order, orders)
                    
                elif user_input_order == "3":
                    order_name = input("Whose order status would you like to update? Press 0 to cancel! ")
                    
                    if order_name == "0":
                        menu_functions.order_menu()
                        
                    for order in orders:
                    
                        if order['customer_name'] == order_name:
                            print("The current status of this order is: ")
                            print(order['status'])
                        
                    new_status = input("What is the new status of this order? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            order['status'] = new_status
                            print("The new order status is: " + new_status)
                    print(orders)
                    
                elif user_input_order == "4":
                    
                    order_name = input("Whose order would you like to update? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            while True:
                                new_order_name = input("Please enter the updated name of the customer: ")
                                if new_order_name != "":
                                    order['customer_name'] = new_order_name
                                new_order_phone = input("Please enter the updated phone number of the customer: ")
                                if new_order_phone != "":
                                    order['customer_phone'] = new_order_phone
                                new_order_address = input("Please enter the updated address of the customer: ")
                                if new_order_address != "":
                                    order['customer_address'] = new_order_address
                                print("The available couriers are:")
                                
                                text_functions.courier_list_select()
                                
                                order['status'] = "Preparing"
                                print("The available items are:")
                                text_functions.product_list_select()
                                
                                break
                                
                            
                elif user_input_order == "5":
                    order_name = input("Whose order would you like to delete? ")
                    
                    for order in orders:
                        
                        if order['customer_name'] == order_name:
                            
                            update_functions.delete_dict_in_list(order, orders)
                            
                elif user_input_order == "6":
                    break
                    menu_functions.main_menu()
                user_input_order = menu_functions.order_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "4":
            print("Your data has been saved, you will now exit the app")
            # save_functions.save_dict_products_to_csv("products.csv", products)
            # save_functions.save_dict_couriers_to_csv("couriers.csv", couriers)
            save_functions.save_dict_to_csv("orders.csv", orders)
            exit()
            
        elif user_input_main == "0":
            menu_functions.main_menu() 
def RunApp():
    user_input_main = menu_functions.main_menu()
    while user_input_main != "0":

        if user_input_main == "1":
            user_input_product = menu_functions.product_menu()

            while user_input_product != 5:

                if user_input_product == "1":
                    print_functions.print_list(products)

                elif user_input_product == "2":
                    new_product = input(
                        "What product would you like to add? (Press 0 to cancel!) "
                    )

                    if new_product == "0":
                        menu_functions.product_menu()
                    update_functions.add_item_to_list(new_product, products)
                    save_functions.save_lists("products.txt", products)

                elif user_input_product == "3":
                    update_product = input(
                        "What product would you like to update? (Press 0 to cancel!)"
                    )

                    if update_product == "0":
                        menu_functions.product_menu()
                    updated_product = input(
                        "What would you like to update this to? (Press 0 to cancel!)"
                    )

                    if update_product == "0":
                        menu_functions.product_menu()
                    update_functions.update_item_in_list(
                        update_product, updated_product, products)

                elif user_input_product == "4":
                    delete_product = input(
                        "What product would you like to delete? (Press 0 to cancel!)"
                    )

                    if delete_product == "0":
                        menu_functions.product_menu()
                    update_functions.delete_item_in_list(
                        delete_product, products)

                elif user_input_product == "5":

                    break
                else:
                    print("Bye Bye")
                    sys.exit()
                user_input_product = menu_functions.product_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "2":
            user_input_courier = menu_functions.courier_menu()

            while user_input_courier != 5:

                if user_input_courier == "1":
                    print_functions.print_list(couriers)

                elif user_input_courier == "2":
                    new_courier = input(
                        "Which courier would you like to add? (Press 0 to cancel!)"
                    )

                    if new_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.add_item_to_list(new_courier, couriers)
                    save_functions.save_lists("couriers.txt", couriers)

                elif user_input_courier == "3":
                    delete_courier = input(
                        "Which courier would you like to delete? (Press 0 to cancel!)"
                    )

                    if delete_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.delete_item_in_list(
                        delete_courier, couriers)

                elif user_input_courier == "4":
                    update_courier = input(
                        "Which name would you like to update? (Press 0 to cancel!)"
                    )

                    if update_courier == "0":
                        menu_functions.courier_menu()
                    updated_courier = input(
                        "What name you like to update this to? (Press 0 to cancel!)"
                    )

                    if updated_courier == "0":
                        menu_functions.courier_menu()
                    update_functions.update_item_in_list(
                        update_courier, updated_courier, couriers)
                    save_functions.save_lists("couriers.txt", couriers)
                elif user_input_courier == "5":
                    break
                user_input_courier = menu_functions.courier_menu()
            user_input_main = menu_functions.main_menu()
        elif user_input_main == "3":
            user_input_order = menu_functions.order_menu()

            while user_input_order != 6:

                if user_input_order == "1":
                    print_functions.print_list(orders)

                elif user_input_order == "2":
                    new_order_name = input(
                        "Please enter the name of the customer: ")
                    new_order_phone = input(
                        "Please enter the phone number of the customer: ")
                    new_order_address = input(
                        "Please enter the address of the customer: ")
                    print("The available couriers are::")
                    print(couriers)
                    new_order_courier = input(
                        "Please enter the courier you would like to deliver the order: "
                    )
                    new_order = {
                        "customer_name": new_order_name,
                        "customer_phone": new_order_phone,
                        "customer_address": new_order_address,
                        "courier": new_order_courier,
                        "status": "Preparing"
                    }

                    update_functions.add_dict_to_list(new_order, orders)
                    save_functions.save_dict_to_csv("orders.csv", new_order)

                elif user_input_order == "3":
                    order_name = input(
                        "Whose order status would you like to update? Press 0 to cancel! "
                    )

                    if order_name == "0":
                        menu_functions.order_menu()

                    for order in orders:

                        if order['customer_name'] == order_name:
                            print("The current status of this order is: ")
                            print(order['status'])

                    new_status = input(
                        "What is the new status of this order? ")

                    for order in orders:

                        if order['customer_name'] == order_name:
                            order['status'] = new_status
                            print("The new order status is: " + new_status)
                    print(orders)

                elif user_input_order == "4":

                    order_name = input(
                        "Whose order would you like to update? ")

                    for order in orders:

                        if order['customer_name'] == order_name:
                            while True:
                                new_order_name = input(
                                    "Please enter the updated name of the customer: "
                                )
                                if new_order_name != "":
                                    order['customer_name'] = new_order_name
                                new_order_phone = input(
                                    "Please enter the updated phone number of the customer: "
                                )
                                order['customer_phone'] = new_order_phone
                                if new_order_phone == " ":
                                    pass
                                new_order_address = input(
                                    "Please enter the updated address of the customer: "
                                )
                                order['customer_address'] = new_order_address
                                if new_order_address == " ":
                                    pass
                                print("The available couriers are::")
                                print(couriers)
                                new_order_courier = input(
                                    "Please enter the courier you would like to deliver the order: "
                                )
                                order['courier'] = new_order_courier
                                order['status'] = "Preparing"
                                if new_order_courier == " ":
                                    pass
                                break
                                # update_functions.add_dict_to_list(order, orders)

                elif user_input_order == "5":
                    order_name = input(
                        "Whose order would you like to delete? ")

                    for order in orders:

                        if order['customer_name'] == order_name:

                            update_functions.delete_dict_in_list(order, orders)

                elif user_input_order == "6":
                    save_functions.save_dict_to_csv("orders.csv", orders)
                    break
                    menu_functions.main_menu()
                user_input_order = menu_functions.order_menu()
            user_input_main = menu_functions.main_menu()

        elif user_input_main == "0":
            menu_functions.main_menu()
import d20pfsrd_classes
from menu_functions import startup, main_menu

#------------------ Sources -------------------#
d21 = d20pfsrd_classes.d20pfsrd(
    6, 'https://www.d20pfsrd.com/magic-items/potions')
d22 = d20pfsrd_classes.d20pfsrd(4,
                                'https://www.d20pfsrd.com/magic-items/rings')
d23 = d20pfsrd_classes.d20pfsrd(5,
                                'https://www.d20pfsrd.com/magic-items/staves')
wr1 = d20pfsrd_classes.scribe()

#-------- File handler for dynamic menu -------#
fh1 = d20pfsrd_classes.File_Handler()
menu_items = fh1.Open_File('menu.json')

#--------- Datacard Create Example ------------#
potions = d21.list_generator(
    4, 3, 0, 5
)  #(number of colums, number of rollchart columns, start column, end column)
wr1.write_json(potions, 'potions.json')
#----------- Append Example -------------------#
# wr1.append_json('rings.json',[{'fake':'list'},{'fake2':'list2'}])

rings = d22.list_generator(4, 1, 0, 3)
wr1.write_json(rings, 'rings.json')

#startup()
main_menu()
def RunApp(connection):
    valid_options = ["1", "2", "3", "4", "0"]

    user_input_main = validation_functions.validity_checker(
        valid_options, menu_functions.main_menu())
    while user_input_main != "0":

        if user_input_main == "1":
            os.system('clear')

            valid_options = ["1", "2", "3", "4", "5", "0"]

            user_input_product = validation_functions.validity_checker(
                valid_options, menu_functions.product_menu())

            while user_input_product != 5:

                if user_input_product == "1":

                    print_functions.read_product_data_from_db(connection)

                    menu_functions.sub_menu('Product', connection)

                elif user_input_product == "2":
                    update_functions.add_product_in_db(connection)

                    os.system('clear')

                elif user_input_product == "3":
                    update_functions.update_product_in_db(connection)

                    os.system('clear')

                elif user_input_product == "4":
                    update_functions.delete_product_in_db(connection)

                    os.system('clear')

                elif user_input_product == "5":
                    os.system('clear')

                    break

                user_input_product = validation_functions.validity_checker(
                    valid_options, menu_functions.product_menu())

            user_input_main = validation_functions.validity_checker(
                valid_options, menu_functions.main_menu())

        elif user_input_main == "2":
            os.system('clear')

            valid_options = ["1", "2", "3", "4", "5", "0"]

            user_input_courier = validation_functions.validity_checker(
                valid_options, menu_functions.courier_menu())

            while user_input_courier != 5:

                if user_input_courier == "1":
                    print_functions.read_courier_data_from_db(connection)

                    menu_functions.sub_menu('Courier', connection)

                elif user_input_courier == "2":
                    update_functions.add_courier_to_db(connection)

                    os.system('clear')

                elif user_input_courier == "3":
                    update_functions.delete_courier_in_db(connection)

                    os.system('clear')

                elif user_input_courier == "4":
                    update_functions.update_courier_in_db(connection)

                    os.system('clear')

                elif user_input_courier == "5":
                    os.system('clear')

                    break

                user_input_courier = validation_functions.validity_checker(
                    valid_options, menu_functions.courier_menu())

            user_input_main = validation_functions.validity_checker(
                valid_options, menu_functions.main_menu())

        elif user_input_main == "3":
            os.system('clear')

            valid_options = ["1", "2", "3", "4", "5", "6", "0"]

            user_input_order = validation_functions.validity_checker(
                valid_options, menu_functions.order_menu())

            while user_input_order != 6:

                if user_input_order == "1":

                    print_functions.read_order_data_from_db(connection)

                    menu_functions.sub_menu('Order', connection)

                elif user_input_order == "2":
                    update_functions.add_order_to_db(connection)

                    os.system('clear')

                elif user_input_order == "3":
                    update_functions.update_order_status_in_db(connection)

                    os.system('clear')

                elif user_input_order == "4":
                    update_functions.update_order_in_db(connection)

                    os.system('clear')

                elif user_input_order == "5":
                    update_functions.delete_order_in_db(connection)

                    os.system('clear')

                elif user_input_order == "6":
                    os.system('clear')

                    break

                    menu_functions.main_menu()

                user_input_order = validation_functions.validity_checker(
                    valid_options, menu_functions.order_menu())

            user_input_main = validation_functions.validity_checker(
                valid_options, menu_functions.main_menu())

        elif user_input_main == "4":
            os.system('clear')
            print("Your data has been saved, you will now exit the app")

            connection.close()

            exit()

        elif user_input_main == "0":
            print(
                "You are now exiting the application, thankyou for using the ProductApp!"
            )
            os.system('clear')

            connection.close()

            exit()
Exemple #5
0
import sqlite3
from menu_functions import main_menu

conn = sqlite3.connect('DATABASE.sqlite')
conn.row_factory = sqlite3.Row

c = conn.cursor()

# Main Menu
commit = main_menu(c)

if commit:
    conn.commit()

conn.close()