From 4da733a375e345537e520f3fbb33d1f35dcdf019 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 13 Jan 2020 11:05:53 -0500 Subject: [PATCH 1/3] Add logging --- main.py | 60 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index cff3b81..be70219 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import yaml +import logging #import wx #app = wx.App() @@ -8,11 +9,12 @@ #app.MainLoop() fruits_list = [] +logging.basicConfig(level=logging.debug) # Set the logging level def find_aisle(search_item): for aisle in fruits_list["aisle"]: for item in aisle: - print(item) + logging.debug(item) if search_item == item : return aisle return None @@ -21,34 +23,34 @@ def find_aisle(search_item): with open(r'data/stores.yaml') as file: fruits_list = yaml.safe_load(file) - print(fruits_list) - print(fruits_list["aisle"]["1"]) + #logging.debug(fruits_list) + #logging.debug(fruits_list["aisle"]["1"]) list_of_all_things_in_isle_1 = fruits_list["aisle"]["1"] -print(find_aisle("beans")) - -#This sets the store location, which has different items in different locations. -count = False -store = input("Where are you shopping?: ") -while count == False: - #if store == "Hannaford" or store == "hannaford": - if store.upper() == "hannaford".upper(): - store_items = [] - aisle_location = [] - count = True - elif "sam".upper() in store.upper(): - store_items = [] - aisle_location = [] - count = True - else: - print ("Sorry, I don't recognize that store, try again.") - store = input("Where are you shopping?: ") - -#This sets the items in the shopping list for comparison and sorting. -list_count = int(input("How many items are on your shopping list?: ")) -shopping_list = [] -shopping_list_final = [] -for i in range(list_count): - item = input("Enter item: ") - shopping_list.append(item) +logging.info(find_aisle("beans")) +if __name__ == "__main__": # Run only if this is the main file + #This sets the store location, which has different items in different locations. + count = False + store = input("Where are you shopping?: ") + while count == False: + #if store == "Hannaford" or store == "hannaford": + if store.upper() == "hannaford".upper(): + store_items = [] + aisle_location = [] + count = True + elif "sam".upper() in store.upper(): + store_items = [] + aisle_location = [] + count = True + else: + print ("Sorry, I don't recognize that store, try again.") + store = input("Where are you shopping?: ") + + #This sets the items in the shopping list for comparison and sorting. + list_count = int(input("How many items are on your shopping list?: ")) + shopping_list = [] + shopping_list_final = [] + for i in range(list_count): + item = input("Enter item: ") + shopping_list.append(item) From 95800132d77635ff2578297fbd3f11a55180bfed Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 13 Jan 2020 11:24:00 -0500 Subject: [PATCH 2/3] Renamed stores.yaml to store1 as all stores have isles, fixed search issue --- data/store1.yaml | 77 +++++++++++++++++++++++++++++++++++++++++++++++ data/stores.yaml | 78 ------------------------------------------------ main.py | 26 +++++++++------- 3 files changed, 93 insertions(+), 88 deletions(-) create mode 100644 data/store1.yaml delete mode 100644 data/stores.yaml diff --git a/data/store1.yaml b/data/store1.yaml new file mode 100644 index 0000000..8f8d69c --- /dev/null +++ b/data/store1.yaml @@ -0,0 +1,77 @@ +"1": + - "mexican" + - "international" + - "gourmet" + - "pasta" + - "pizza dough" + - "pizza sauce" + - "rice" +"2": + - "asain foods" + - "bbq sauce" + - "beans" + - "mayo" + - "mustard" + - "relish" + - "salad dressing" + - "shortening" + - "soups" + - "canned vegetables" +"3": + - "baking needs" + - "baking" + - "bake ware" + - "cake mixes" + - "cake decor" + - "chocolate chips" + - "coconut" + - "cooking oil" + - "flour" + - "canned fruits" + - "gravy" + - "jams/jellies" + - "pudding" + - "salt" + - "spices" + - "stuffing" + - "sugar" + - "peanut butter" +"4": + - "cereal" + - "granola" + - "Honey" + - "oats" + - "pancake mix" +"5": + - "bread" + - "cocoa" + - "coffee" + - "syrup" + - "tea" +"6": + - "juices" + - "seltzer" +"7": + - "cookies" + - "crackers" + - "soda" +"8": +"9": + - "chips" + - "seasonal" +"10": + - "aluminum foil" + - "freezer wrap" + - "napkins" + - "tissues" +"11": + - "matches" +"12": + - "house" + - "mop" + - "broom" + - "cleaning" +"13": + - "nuts" +"14": + - "frozen foods" diff --git a/data/stores.yaml b/data/stores.yaml deleted file mode 100644 index beda812..0000000 --- a/data/stores.yaml +++ /dev/null @@ -1,78 +0,0 @@ -aisle: - "1": - - "mexican" - - "international" - - "gourmet" - - "pasta" - - "pizza dough" - - "pizza sauce" - - "rice" - "2": - - "asain foods" - - "bbq sauce" - - "beans" - - "mayo" - - "mustard" - - "relish" - - "salad dressing" - - "shortening" - - "soups" - - "canned vegetables" - "3": - - "baking needs" - - "baking" - - "bake ware" - - "cake mixes" - - "cake decor" - - "chocolate chips" - - "coconut" - - "cooking oil" - - "flour" - - "canned fruits" - - "gravy" - - "jams/jellies" - - "pudding" - - "salt" - - "spices" - - "stuffing" - - "sugar" - - "peanut butter" - "4": - - "cereal" - - "granola" - - "Honey" - - "oats" - - "pancake mix" - "5": - - "bread" - - "cocoa" - - "coffee" - - "syrup" - - "tea" - "6": - - "juices" - - "seltzer" - "7": - - "cookies" - - "crackers" - - "soda" - "8": - "9": - - "chips" - - "seasonal" - "10": - - "aluminum foil" - - "freezer wrap" - - "napkins" - - "tissues" - "11": - - "matches" - "12": - - "house" - - "mop" - - "broom" - - "cleaning" - "13": - - "nuts" - "14": - - "frozen foods" diff --git a/main.py b/main.py index be70219..5944240 100644 --- a/main.py +++ b/main.py @@ -9,26 +9,32 @@ #app.MainLoop() fruits_list = [] -logging.basicConfig(level=logging.debug) # Set the logging level +logging.basicConfig(level=logging.INFO) # Set the logging level def find_aisle(search_item): - for aisle in fruits_list["aisle"]: - for item in aisle: - logging.debug(item) - if search_item == item : - return aisle + for aisle, items in fruits_list.items(): #.iteritems() for python 2 + logging.debug("Currently looking at aisle " + str(aisle)) + try: + for item in items: + logging.debug("Currently checking item " + str(item).upper() + ", Looking for " + str(search_item).upper()) + if str(search_item).upper() == str(item).upper() : + logging.info("Found item " + str(item) + " in aisle " + str(aisle)) + return aisle + except: + logging.warning("Error, no items in row: " + str(aisle)) return None -with open(r'data/stores.yaml') as file: +with open(r'data/store1.yaml') as file: fruits_list = yaml.safe_load(file) #logging.debug(fruits_list) #logging.debug(fruits_list["aisle"]["1"]) - list_of_all_things_in_isle_1 = fruits_list["aisle"]["1"] + list_of_all_things_in_isle_1 = fruits_list["1"] -logging.info(find_aisle("beans")) -if __name__ == "__main__": # Run only if this is the main file +logging.info("Searched for item nuts and found item in: " + str(find_aisle("nuts"))) + +if __name__ == "_main__": # Run only if this is the main file #This sets the store location, which has different items in different locations. count = False store = input("Where are you shopping?: ") From 5abf8ae9c7219b5a335f1d67decd11c69e2f2a47 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 13 Jan 2020 11:58:23 -0500 Subject: [PATCH 3/3] Add Comments --- main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 5944240..4c473a7 100644 --- a/main.py +++ b/main.py @@ -9,20 +9,20 @@ #app.MainLoop() fruits_list = [] -logging.basicConfig(level=logging.INFO) # Set the logging level +logging.basicConfig(level=logging.INFO) # Set the logging level (setting it lower will display more messages) def find_aisle(search_item): for aisle, items in fruits_list.items(): #.iteritems() for python 2 - logging.debug("Currently looking at aisle " + str(aisle)) - try: - for item in items: - logging.debug("Currently checking item " + str(item).upper() + ", Looking for " + str(search_item).upper()) - if str(search_item).upper() == str(item).upper() : - logging.info("Found item " + str(item) + " in aisle " + str(aisle)) - return aisle - except: - logging.warning("Error, no items in row: " + str(aisle)) - return None + logging.debug("Currently looking at aisle " + str(aisle)) # Send a message to the logger + try: # Try doing the following + for item in items: # For every item in all the items in an aisle + logging.debug("Currently checking item " + str(item).upper() + ", Looking for " + str(search_item).upper()) # log what we're looking for + if str(search_item).upper() == str(item).upper() : # Check if true + logging.info("Found item " + str(item) + " in aisle " + str(aisle)) # Log that we found an item + return aisle # Return the aisle that item exists in + except: # If something above failed + logging.warning("Error, no items in row: " + str(aisle)) # Trow an error + return None # If nothing above worked, return that the item could not be found with open(r'data/store1.yaml') as file: @@ -32,7 +32,7 @@ def find_aisle(search_item): #logging.debug(fruits_list["aisle"]["1"]) list_of_all_things_in_isle_1 = fruits_list["1"] -logging.info("Searched for item nuts and found item in: " + str(find_aisle("nuts"))) +logging.info("Searched for item nuts and found item in: " + str(find_aisle("nuts"))) # Log this if __name__ == "_main__": # Run only if this is the main file #This sets the store location, which has different items in different locations.