diff options
| author | 2018-07-25 13:43:13 +0100 | |
|---|---|---|
| committer | 2018-07-25 13:43:13 +0100 | |
| commit | b8145dd60d66c02be407d87d3f629d67512dba15 (patch) | |
| tree | a3a165220cc7b010f4785bb8e5863df90bd4237e | |
| parent | add !gtin to upc.py (diff) | |
| signature | ||
support optional data in upc.py
| -rw-r--r-- | modules/upc.py | 30 |
1 files 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") |
