Beispiel #1
0
def total_stock_value():
    clear()
    print_header(" Total stock value ")
    total = 0.0
    for item in catalog:
        total += item.stock * item.price
    print("The total is: $" + str(total))
Beispiel #2
0
def three_expensive_items():
    clear()
    print_header("Three Most Expensive Items")
    temp = sorted(catalog, key=lambda item: item.price)
    print_item(temp[-1])
    print_item(temp[-2])
    print_item(temp[-3])
Beispiel #3
0
def game():
    menu.printLogo()
    menu.startScreen()
    menu.clear()
    menu.printLogo()
    menu.hero_menu()
    menu.clear()
    menu.printLogo()
    menu.select_map()
Beispiel #4
0
def display_items_out_of_stock():
    clear()
    print_header(" Items out of stock ")
    if(len(catalog) == 0):
        print(" ** No items to display")
    else:
        for item in catalog:
            if(item.stock == 0):
                print_item(item)
Beispiel #5
0
def display_categories():
    clear()
    print_header("Categories")
    cat_list = []
    i = 1
    for item in catalog:
        if item.category not in cat_list:
            cat_list.append(item.category)
            print("\n" + str(i) + ": " + item.category)
            i = i + 1
Beispiel #6
0
def lowest_cost_item():
    clear()
    print_header("Cheapest Item")
    temp = []
    for item in catalog:
        temp.append(item.price)
        temp = sorted(temp)
    for item in catalog:
        if (item.price == temp[0]):
            print_item(item)
def parse(dic):
    # takes dict as param
    # repr json data
    # iterate over every key, and print element at that key
    print("\n**********************")
    for key in dic.keys():
        print(key + " : " + str(dic[key]))
    print("\n**********************\n")
    input("Press Enter to continue....")
    menu.clear()
def listParse(list):
    # takes list as param
    # list contains dic
    print("\n**********************")
    for dic in list:
        for key in dic.keys():
            print(key + " : " + str(dic[key]))
        print("\n", end="")
    print("\n**********************\n")
    input("Press Enter to continue....")
    menu.clear()
Beispiel #9
0
def display_categories():
    clear()
    print_header("  Categories  ")
    categories = []
    for item in catalog:
        if( item.category.lower() not in (category.lower() for category in categories) ):
            categories.append(item.category)
            print(item.category)

    if(len(categories) == 0):
        print("*** No categories to display ***")
Beispiel #10
0
def cheapest_product():
    clear()
    print_header("  Cheapest Product  ")
    if(len(catalog) == 0):
        print("*** No products in the catalog ***")
    else:
        cheapest_item = catalog[0]
        for item in catalog:
            if(item.price < cheapest_item.price ):
                cheapest_item = item
        print("The Cheapest product it is:")
        print_item(cheapest_item)
Beispiel #11
0
def three_expensive_products():
    clear()
    print_header("  3 most expensive products  ")
    temp = []
    if(len(catalog) == 0):
        print("*** No products in the catalog ***")
    else:
        temp  = sorted(catalog, key=lambda x: x.price, reverse=True)
        count = 0
        for item in temp:
            print_item(item)
            count+=1
            if(count == 3):
                break
Beispiel #12
0
def rmSubscribe():
    menu.clear()
    choice = input("Remove all subscriptions (y/n): ")
    if (choice == 'y'):
        if (name != 'nt'):
            system("rm " + constants.RELATED)
            system("rm " + constants.DATE)
        else:
            system("del " + constants.RELATED)
            system("del " + constants.DATE)
        schedule.rmSchedule()
        exit(0)
    else:
        menu.clear()
        choice = input("Name to unsubscribe: ")
        filehandlers.rmSpecific(choice.lower())
Beispiel #13
0
def select_map():
    size = input("""
                                        Select size of the map:
                                            1. Small (4x4)
                                            2. Medium (5x5)
                                            3. Large (8x8)

                                            --->""")
    choice_menu = {'1': small(), '2': medium(), '3': large()}
    if size not in choice_menu.keys():
        menu.clear()
        menu.printLogo()
        print("Please pick a number")
        sleep(0.5)
        size = 0
        select_map()
    else:
        return choice_menu[size]
Beispiel #14
0
def subscribe(schedule_script, scheduled):
    # takes script to schedule as parameter
    # clear previous subscriptions
    # asks user which country to subscribe
    # type of data to subscribe
    # create a file containing subscription details
    # schedule given script
    country = input("Country to subscribe: ")
    menu.clear()
    print("Type of Subscription:")
    print("1. Get status by Country")
    print("2. Difference between Latest state and previous one by country")
    type_subscription = int(input("Choose> "))
    menu.clear()
    subscription_data = {'country': country.lower(), 'type': type_subscription}
    with open(constant.SUBSCRIPTION, 'a') as subscription_file:
        subscription_file.writelines(str(subscription_data) + "\n")
    if (isScheduled(scheduled) == 0):
        scheduler.schedule(schedule_script, scheduled)
Beispiel #15
0
 def start_point(self):
     menu.clear()
     menu.printLogo()
     corner = input("""
                                     Where do you want to start?
                                         1. North west
                                         2. North east
                                         3. South west
                                         4. South east
                                         
                                         --->""")
     if corner == "1":
         return (0, 0)
     elif corner == "2":
         return (0, self.map_size - 1)
     elif corner == "3":
         return (self.map_size - 1, 0)
     elif corner == "4":
         return (self.map_size - 1, self.map_size - 1)
Beispiel #16
0
def rmSubscribe(schedule_script, scheduled):
    # remove subscription
    # clear subscription data
    # remove from schedule jobs
    # call corresponding func based on OS
    menu.clear()
    print("Unsuscribe")
    choice = (userInput.read("Remove All Subscription (y/n): ")).lower()
    if (choice == 'y'):
        if (name == 'nt'):
            scheduler.rmScheduleWindows(schedule_script)
            system("del " + constant.SUBSCRIPTION)
            #system("del " + constant.BASH_SCRIPT)
            system("del " + constant.SCHEDULED)
            #system("del " + constant.LOG)
        else:
            scheduler.rmScheduleLinux(schedule_script)
            system("rm " + constant.SUBSCRIPTION)
            system("rm " + constant.BASH_SCRIPT)
            system("rm " + constant.SCHEDULED)
            #system("rm " + constant.LOG)
        setScheduled(scheduled, str(0))

        #exit(0)

    else:
        country = (userInput.read("Country to Unsubscribe")).lower()
        print("Type of Subscription")
        print("1. Get status by Country")
        print("2. Difference between Latest state and previous one by country")
        type_subscription = int(input("Choose> "))
        menu.clear()
        infos = []
        with open(constant.SUBSCRIPTION, 'r') as subscription_file:
            for line in subscription_file:
                data = literal_eval(line)
                if (data['country'] != country
                        or data['type'] != type_subscription):
                    infos.append(data)
        with open(constant.SUBSCRIPTION, 'w') as subscription_file:
            for info in infos:
                subscription_file.write(str(info) + "\n")
Beispiel #17
0
def mainMenu():
	while True:
		try:
			clear()
			print '-' * 14 
			print 'Payroll System'
			print '-' * 14 
			print '\nWhat would you like to do?'
			print '-' * 26
			print '1.) View employee report'
			print '2.) Add new employee'
			print '3.) Update employee'
			print '4.) Remove employee'
			print '5.) Exit'
			mainMenuAnswer = input('--> ')
			if mainMenuAnswer <  1 or mainMenuAnswer > 5:
				raw_input('Invalid selection. Press ENTER to try again.')
			else:
				return mainMenuAnswer
		except (NameError, SyntaxError):
			raw_input('Invalid selection. Press ENTER to try again.')
Beispiel #18
0
def mainMenu():
    while True:
        try:
            clear()
            print '-' * 14
            print 'Payroll System'
            print '-' * 14
            print '\nWhat would you like to do?'
            print '-' * 26
            print '1.) View employee report'
            print '2.) Add new employee'
            print '3.) Update employee'
            print '4.) Remove employee'
            print '5.) Exit'
            mainMenuAnswer = input('--> ')
            if mainMenuAnswer < 1 or mainMenuAnswer > 5:
                raw_input('Invalid selection. Press ENTER to try again.')
            else:
                return mainMenuAnswer
        except (NameError, SyntaxError):
            raw_input('Invalid selection. Press ENTER to try again.')
Beispiel #19
0
def register_item():
    global last_id
    clear()
    try:
        print_header(" Register new Item ")
        title = input("Please provide the Title: ")
        category = input("Please provide the Category: ")
        stock = int(input("Please provide the Stock: "))
        price = float(input("Please provide the Price: "))

        the_item = Item(last_id,title,category,stock,price)
        last_id+=1
        # add the obj to the list

        catalog.append(the_item)

        print("\n  Item saved, you have " + str(len(catalog)) + " items in your catalog")
        serialize_catalog()
    except ValueError:
        print("*Error, provide valid numbers!")
    except:
        print("*Error, verify data and try again!")
def register_item():
    global last_id
    clear()
    header("Register an item")

    title = input("New item title: ")
    cat = input("New item category: ")
    price = float(input("New item price: "))
    stock = int(input("New item stock: "))        
            

    new_item = Item() # how to create new objects
    last_id += 1
    new_item.id = last_id
    new_item.title = title
    new_item.category = cat
    new_item.price = price
    new_item.stock = stock

    catalog.append(new_item)
    add_log_events("New Item", "Added item: " + str(last_id))
    print("Item created!")
Beispiel #21
0
def game():
    menu.printLogo()
    menu.startScreen()
    menu.clear()
    menu.printLogo()
    hero = menu.hero_menu()
    menu.clear()
    menu.printLogo()

    ds = Dungeon(menu.select_map())
    coordinates = ds.start_room
    ds.print_dungeon(coordinates)
    while True:
        if_escape = True
        menu.clear()
        menu.printLogo()

        check_room = check(hero, ds, coordinates)

        if check_room[0]:
            return_value = menu.attack_menu()
            x = coordinates[0]
            y = coordinates[1]
            if return_value == "attack":
                battle.attack(hero, sort(ds.dungeon[x][y].monsters))
                ds.dungeon[coordinates[0]][coordinates[1]].monsters = [
                ]  #Clear monster from Room Object
                ds.dungeon[coordinates[0]][coordinates[1]].marker = '[X]'
            elif return_value == "escape":
                battle.escape(hero, sort(ds.dungeon[x][y].monsters))
                if_escape = False

        if check_room[1]:
            if if_escape == True:
                hero.points += coinCount(
                    check_room[1])  # Adds sum of treasures to Hero's attribute
                print(f"Collected so far: {hero.points}g")
                ds.dungeon[coordinates[0]][coordinates[1]].treasure = [
                ]  #Clear treasure from Room Object
                ds.dungeon[coordinates[0]][coordinates[1]].marker = '[X]'
        else:
            print("""
                                            Room is empty""")
            ds.dungeon[coordinates[0]][coordinates[1]].marker = '[X]'

        ds.print_dungeon(coordinates)
        direction = print_move()
        coordinates = ds.move(direction, coordinates)
        if (item.price == temp_prices[1]):
            print_item(item)

    for item in catalog:
        if (item.price == temp_prices[2]):
            print_item(item)


# instructions
deserialize_catalog()
input('Press Enter to continue...'
      )  #putting input bc otherwise it'll go to 'clear'

opc = ''
while (opc != 'x'):
    clear()
    print_menu()
    opc = input('Please select an option: ')
    print(opc)

    if (opc == '1'):
        register_item()
        serialize_catalog()

    elif (opc == '2'):
        # create a function, call, travel the list and display the title.title
        display_catalog()

    elif (opc == '3'):
        out_of_stock()
        # call the fn
Beispiel #23
0
def attack(hero, list_of_monsters): #TODO Endurance to be change to Stamina to match other changes
    menu.clear()
    menu.printLogo()

    while list_of_monsters:
        input(f"""
                                You charge heroically towards the {list_of_monsters[0].name}!

                                        Press any key to enter battle""")
        menu.clear()
        menu.printLogo()
        print("""           
                                                                    (User turn)""")
        
        menu.roll_dice()
        time.sleep(1)
        menu.clear()
        menu.printLogo()

        go = True
        shield_block = True
        while go:
            if die.die(hero.attack) > die.die(list_of_monsters[0].agility):
                if isinstance(hero, Heroes.Thief) and (random.randint(0, 100) <= 25): #Thief Special Ability
                    print("""
                                    As Thief you inflicted Critical Damage! Causing 2 Damage!""")
                    list_of_monsters[0].endurance -= 2
                else: # If Hero's attack is larger than monster's agility, inflict 1 dmg
                    print("""           
                                                                    (User turn)""")

                    print(f"""
                    {list_of_monsters[0].name} health: {list_of_monsters[0].endurance}             VS              Your health: {hero.endurance}""")
                    
                    print("""

                                Successfull roll! Monster takes 1 damage
                                                Nice hit!
                    """)
                    list_of_monsters[0].endurance -= 1
                    
                    time.sleep(2)
                    if list_of_monsters[0].endurance <= 0:
                        time.sleep(0.5)
                        print(f"""
                                            {list_of_monsters[0].name} slain!
                                               GG WP""")
                        del list_of_monsters[0] 
                        input("""  
                                    press any key to continue""")
                        menu.clear()
                        menu.printLogo()
                        go = False
                        break
                    else:
                        input(f"""

                                     The {list_of_monsters[0].name} swings at you!

                                   Press any key to defend yourself!""")
                    menu.clear()
                    menu.printLogo()
                    print("""
                    (Enemy turn)""")
                    menu.roll_dice()
                    time.sleep(1)

            else:
                print("""           
                                                                    (User turn)""")
                print("""
                                        Your attack missed!""")

            
            if die.die(list_of_monsters[0].attack) > die.die(hero.agility):
                #menu.clear()
                #menu.printLogo
                print("""
                    (Enemy turn)""")
                menu.roll_dice()
                time.sleep(2)
                menu.clear()
                menu.printLogo()
                print(f"""
                    {list_of_monsters[0].name} health: {list_of_monsters[0].endurance}             VS              Your health: {hero.endurance}""")
                
                time.sleep(1)
                print("""
                                     Monster attacks you for 1 damage!""")
                time.sleep(2)
                menu.clear()
                menu.printLogo()
                if isinstance(hero, Heroes.Knight) and shield_block == True: #Knight special abilitie
                    print("""
                                    First attack blocked by your shield!""")
                    shield_block = False
                else:
                    hero.endurance -= 1
                    print(f"""
                    {list_of_monsters[0].name} health: {list_of_monsters[0].endurance}             VS              Your health: {hero.endurance}""")
                    input("""
                                      OUCH! That hurt...

                              Press any key to start your turn""")
                    menu.clear()
                    menu.printLogo()
                    print("""           
                                                                (User turn)""")
                    menu.roll_dice()
                    time.sleep(1)
                    menu.clear()
                    menu.printLogo()
        
            elif list_of_monsters[0].endurance > 0:
                menu.clear()
                menu.printLogo()
                print("""
                    (Enemy turn)""")
                print(f"""
                    {list_of_monsters[0].name} health: {list_of_monsters[0].endurance}             VS              Your health: {hero.endurance}""")
                print("""
                                        Monster attack missed
                        """)
                time.sleep(1.5)
                input("""
                                        That was a close one!

                                    Press any key to start your turn""")
                menu.clear()
                menu.printLogo()
                print("""           
                                                                (User turn)""")
                menu.roll_dice()
                time.sleep(1)
                menu.clear()
                menu.printLogo()

            if hero.endurance == 0:
                go = False
Beispiel #24
0
def main():
    menu.clear()
    constant.init()
    scheduler.init()

    menu.createMenu(constant.API, constant.SCHEDULE_SCRIPT, constant.SCHEDULED)
Beispiel #25
0
def main(mainMenuAnswer):
	if mainMenuAnswer == 1:
		"""Displays employee report table"""
		clear()
		firstName = raw_input('Employee first name: ')
		lastName = raw_input('Employee last name: ')
		clear()
		doesEmployeeExist = employeeCheck(firstName, lastName)
		if doesEmployeeExist == True:
			employee.employeeImport(firstName, lastName)
			employee.printEmployeeReport()
			raw_input('\nPress ENTER to return to the main menu.')
		elif doesEmployeeExist == False:
			print 'No employee record for', firstName, lastName + '.\n'
			raw_input('Press ENTER to return to the main menu.')

	if mainMenuAnswer == 2:
		"""Adds employee to employeeData.xml"""
		clear()
		firstName = raw_input('Employee first name: ')
		lastName = raw_input('Employee last name: ')
		doesEmployeeExist = employeeCheck(firstName, lastName)
		if doesEmployeeExist == True:
			print '\nEmployee already exists.\n'
			print 'Select Update Employee or Add/Remove Employee'
			print 'at the main menu to modify an existing record.\n'
			raw_input('Press ENTER to return to the main menu.')
		elif doesEmployeeExist == False:
			while True:
				try:
					hourlyWage = input('Hourly wage: ')
					if hourlyWage < 0:
						print 'Hourly wage must be higher than zero.'
						raw_input('Press ENTER to input a new wage.')
					else:
						break
				except (NameError, SyntaxError):
					raw_input('Invalid input. Press ENTER to try again.')
			while True:
				try:
					hoursWorked = input('Hours worked: ')
					if hoursWorked < 0:
						print 'Hours worked cannot be less than zero.'
						raw_input('Press ENTER to input a new wage.')
					else:
						break
				except (NameError, SyntaxError):
					raw_input('Invalid input. Press ENTER to try again.')
			while True:
				clear()
				print 'Before the new user is added, please verify the following:\n'
				print 'First Name:', firstName
				print 'Last Name:', lastName
				print 'Hourly Wage: $%.2f/hr' % hourlyWage
				print 'Hours Worked: %.2f' % hoursWorked
				print '\nIs this information correct?'
				isInputCorrect = raw_input('(y/n) --> ')
				if isInputCorrect == 'y':
					addEmployee(firstName, lastName, hourlyWage, hoursWorked)
					print 'Employee successfully added.'
					raw_input('Press ENTER to continue.')
					break
				elif isInputCorrect == 'n':
					print 'No employee information has been saved.'
					raw_input('Press ENTER to return to the main menu.')
					break
				else:
					raw_input('Please answer y or n. Press ENTER to continue.')

	# if mainMenuAnswer == 3:

	# if mainMenuAnswer == 4:

	if mainMenuAnswer == 5:
		clear()
		exit()
Beispiel #26
0
def main(mainMenuAnswer):
    if mainMenuAnswer == 1:
        """Displays employee report table"""
        clear()
        firstName = raw_input('Employee first name: ')
        lastName = raw_input('Employee last name: ')
        clear()
        doesEmployeeExist = employeeCheck(firstName, lastName)
        if doesEmployeeExist == True:
            employee.employeeImport(firstName, lastName)
            employee.printEmployeeReport()
            raw_input('\nPress ENTER to return to the main menu.')
        elif doesEmployeeExist == False:
            print 'No employee record for', firstName, lastName + '.\n'
            raw_input('Press ENTER to return to the main menu.')

    if mainMenuAnswer == 2:
        """Adds employee to employeeData.xml"""
        clear()
        firstName = raw_input('Employee first name: ')
        lastName = raw_input('Employee last name: ')
        doesEmployeeExist = employeeCheck(firstName, lastName)
        if doesEmployeeExist == True:
            print '\nEmployee already exists.\n'
            print 'Select Update Employee or Add/Remove Employee'
            print 'at the main menu to modify an existing record.\n'
            raw_input('Press ENTER to return to the main menu.')
        elif doesEmployeeExist == False:
            while True:
                try:
                    hourlyWage = input('Hourly wage: ')
                    if hourlyWage < 0:
                        print 'Hourly wage must be higher than zero.'
                        raw_input('Press ENTER to input a new wage.')
                    else:
                        break
                except (NameError, SyntaxError):
                    raw_input('Invalid input. Press ENTER to try again.')
            while True:
                try:
                    hoursWorked = input('Hours worked: ')
                    if hoursWorked < 0:
                        print 'Hours worked cannot be less than zero.'
                        raw_input('Press ENTER to input a new wage.')
                    else:
                        break
                except (NameError, SyntaxError):
                    raw_input('Invalid input. Press ENTER to try again.')
            while True:
                clear()
                print 'Before the new user is added, please verify the following:\n'
                print 'First Name:', firstName
                print 'Last Name:', lastName
                print 'Hourly Wage: $%.2f/hr' % hourlyWage
                print 'Hours Worked: %.2f' % hoursWorked
                print '\nIs this information correct?'
                isInputCorrect = raw_input('(y/n) --> ')
                if isInputCorrect == 'y':
                    addEmployee(firstName, lastName, hourlyWage, hoursWorked)
                    print 'Employee successfully added.'
                    raw_input('Press ENTER to continue.')
                    break
                elif isInputCorrect == 'n':
                    print 'No employee information has been saved.'
                    raw_input('Press ENTER to return to the main menu.')
                    break
                else:
                    raw_input('Please answer y or n. Press ENTER to continue.')

    # if mainMenuAnswer == 3:

    # if mainMenuAnswer == 4:

    if mainMenuAnswer == 5:
        clear()
        exit()