pizzapi icon indicating copy to clipboard operation
pizzapi copied to clipboard

store.get_menu() raised an exception

Open DrLatency opened this issue 5 years ago • 3 comments

I was just going through the tutorial but can't get store.get_menu() to work.

My code:

from pizzapi import * customer = Customer('Donald', 'Trump', '[email protected]', '2024561111') address = Address('2175 S 11th Ave', 'Bozeman', 'MT', '59715') store = address.closest_store() menu = store.get_menu()

results in terminal:

from pizzapi import * customer = Customer('Donald', 'Trump', '[email protected]', '2024561111') address = Address('2175 S 11th Ave', 'Bozeman', 'MT', '59715') store = address.closest_store() menu = store.get_menu() customer = Customer('Donald', 'Trump', '[email protected]', '2024561111') address = Address('2175 S 11th Ave', 'Bozeman', 'MT', '59715') store = address.closest_store() menu = store.get_menu() Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pizzapi/store.py", line 24, in get_menu menu = Menu(response, self.country) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pizzapi/menu.py", line 50, in init self.root_categories[key] = self.build_categories(value) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pizzapi/menu.py", line 62, in build_categories new_subcategory = self.build_categories(subcategory, category) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pizzapi/menu.py", line 66, in build_categories raise Exception('PRODUCT NOT FOUND: %s %s' % (product_code, category.code)) Exception: PRODUCT NOT FOUND: 9418 CouponPizza

DrLatency avatar Dec 12 '20 19:12 DrLatency

The following work around seems to do the trick.

Inside of menu.py - comment out line 66 and add a continue statement when the conditional is triggered:

def build_categories(self, category_data, parent=None):
    category = MenuCategory(category_data, parent)
    for subcategory in category_data['Categories']:
        new_subcategory = self.build_categories(subcategory, category)
        category.subcategories.append(new_subcategory)
    for product_code in category_data['Products']:
        if product_code not in self.menu_by_code:
            # raise Exception('PRODUCT NOT FOUND: %s %s' % (product_code, category.code))
            continue
        product = self.menu_by_code[product_code]
        category.products.append(product)
        product.categories.append(category)
    return category

Instead of raising an exception when a product category is not found, it will just skip adding that product category and continue building.

milan-stoj avatar Dec 26 '20 21:12 milan-stoj

i have the same issue ...

anask1234 avatar Apr 16 '22 18:04 anask1234