From b8145dd60d66c02be407d87d3f629d67512dba15 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 25 Jul 2018 13:43:13 +0100 Subject: [PATCH] support optional data in upc.py --- modules/upc.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/upc.py b/modules/upc.py index 90b313b5..37588481 100644 --- a/modules/upc.py +++ b/modules/upc.py @@ -26,20 +26,28 @@ class Module(object): return item = page["items"][0] - brand = item["brand"] + brand = item.get("brand", None) + brand = "" if not brand else "%s - " % brand title = item["title"] - description = item["description"] + description = item.get("description", None) + description = " " if not description else ": %s " % description - weight = item["weight"] - size = item["dimension"] + weight = item.get("weight", None) + weight = weight or "unknown" + size = item.get("dimension", None) + size = size or "unknown" - currency = item["currency"] - lowest_price = item["lowest_recorded_price"] - highest_price = item["highest_recorded_price"] + currency = item.get("currency", None) + lowest_price = item.get("lowest_recorded_price", None) + highest_price = item.get("highest_recorded_price", None) - event["stdout"].write("%s - %s: %s (weight: %s" - ", size: %s, price: %s to %s %s)" % ( - brand, title, description, weight, size, - lowest_price, highest_price, currency)) + pricing = "price: unknown" + if lowest_price and highest_price and currency: + pricing = "price: %s to %s %s" % ( + lowest_price, highest_price, currency) + + event["stdout"].write("%s%s%s(weight: %s" + ", size: %s, price: %s)" % ( + brand, title, description, weight, size, pricing)) else: event["stderr"].write("Failed to load results")