From ed139e5b5942bc747023b6169db8ef60bbb813b6 Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Sun, 14 Jul 2019 15:31:03 +0200 Subject: [PATCH] Port to Python3, canonicalize JSON, retain Umlauts --- examples/products.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/products.py b/examples/products.py index 7c1b8f4..4142de3 100755 --- a/examples/products.py +++ b/examples/products.py @@ -1,10 +1,17 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import print_function + import logging from inema import ProductInformation import json +import sys + +if sys.version_info.major >= 3: + unicode = str + # you have to fill the below with your login details for the ProdWS Service USER = "xxx" PASS = "yyyyyy" @@ -33,7 +40,9 @@ if data['success']: 'max_weight': unicode(weight['maxValue']) } - print json.dumps(products) - + json.dump(products, sys.stdout, + sort_keys=True, indent=4, ensure_ascii=False) + print('') else: - print 'ERROR: %s' % data['Exception'] + print('ERROR: %s' % data['Exception'], file=sys.stderr) + sys.exit(1)