From 972bb621975c4817625ae7bb32c5b0a7de5f3f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Tue, 22 Sep 2015 19:39:20 +0200 Subject: [PATCH] Updated fetch_price script to store store name --- .../amiibo/management/commands/fetch_price.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/amiibofindr/apps/amiibo/management/commands/fetch_price.py b/amiibofindr/apps/amiibo/management/commands/fetch_price.py index ec7fbe2..fda2b87 100644 --- a/amiibofindr/apps/amiibo/management/commands/fetch_price.py +++ b/amiibofindr/apps/amiibo/management/commands/fetch_price.py @@ -13,6 +13,14 @@ from amiibofindr.apps.shop.crawlers import Crawler class Command(BaseCommand): + def update_product(self, product, region): + amiibo_shop = AmiiboShop.objects.get( + item_id=product['shop_product_id'], + shop__flag_code=region[0] + ) + amiibo_shop.shop_name = product.title + amiibo_shop.update_price(product['price'], product['currency']) + def handle(self, *args, **kwargs): regions = Shop.objects.all()\ .order_by('flag_code')\ @@ -27,14 +35,6 @@ class Command(BaseCommand): products = amazon.fetch_batch(item_codes) try: for product in products: - amiibo_shop = AmiiboShop.objects.get( - item_id=product['shop_product_id'], - shop__flag_code=region[0] - ) - amiibo_shop.update_price(product['price'], product['currency']) + self.update_product(product, region) except TypeError: - amiibo_shop = AmiiboShop.objects.get( - item_id=product['shop_product_id'], - shop__flag_code=region[0] - ) - amiibo_shop.update_price(product['price'], product['currency']) + self.update_product(product, region)