diff options
author | Guido Günther <agx@sigxcpu.org> | 2022-12-05 16:54:42 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2022-12-05 17:15:26 +0100 |
commit | d75ec9badf519d648f79d7d1e9f14b98a7393e1f (patch) | |
tree | 3c45570aea82e31e1eb60969b0acd494b23a07f6 | |
parent | 39d101201a25563ac4c3b1e91f71e37bc5eca1e5 (diff) |
Port burner-runtime to python3
-rwxr-xr-x | pellematic-burner-runtime | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/pellematic-burner-runtime b/pellematic-burner-runtime index 7452c23..c9e64d1 100755 --- a/pellematic-burner-runtime +++ b/pellematic-burner-runtime @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # vim: set fileencoding=utf-8 : # # Munin plugin to monitor the burner runtime value @@ -36,7 +36,7 @@ def canon(name): def get_name(item): - if item['name'] in items.keys(): + if item['name'] in list(items.keys()): if item['shortText'] != '???': return item['shortText'] else: @@ -46,19 +46,19 @@ def get_name(item): def print_config(url): - print """graph_title Pellematic Burning Time + print("""graph_title Pellematic Burning Time graph_vlabel Burning time graph_category Heating graph_info This graph shows different hours of burner operation -""" +""") out = fetch_raw(url) for item in out: name = get_name(item) if name: - print "%s.label %s" % (canon(name), name) - print "%s.type GAUGE" % canon(name) + print("%s.label %s" % (canon(name), name)) + print("%s.type GAUGE" % canon(name)) thickness = 1 if name.endswith('soll') else 2 - print "%s.draw LINE%d" % (canon(name), thickness) + print("%s.draw LINE%d" % (canon(name), thickness)) def fetch_raw(url): @@ -86,20 +86,15 @@ def fetch_raw(url): } # The items to fetch are passed as simple json string - payload = json.dumps(items.keys()) + payload = json.dumps(list(items.keys())) r = requests.post(url, data=payload, params=params, cookies=cookies, headers=headers) - - if hasattr(r.json, '__call__'): - ret = r.json() - else: # in requests 0.12 json isn't a callable - ret = r.json - + ret = r.json() if debug: - print >>sys.stderr, ret + print(ret, file=sys.stderr) return ret @@ -108,33 +103,33 @@ def fetch_values(url): for item in out: name = get_name(item) if name: - print "%s.value %s" % (canon(name), item['value']) + print("%s.value %s" % (canon(name), item['value'])) def main(args): if not url: - print >>sys.stderr, "No url configured" + print("No url configured", file=sys.stderr) return 1 if len(args) > 1: if args[1] in [ 'autoconf', 'detect' ]: try: fetch_raw(url) - print "yes" + print("yes") return 0 except: - print "no" + print("no") return 1 elif args[1] == 'config': try: print_config(url) except Exception as e: - print >>sys.stderr, "Failed to fetch config: '%s'" % e + print("Failed to fetch config: '%s'" % e, file=sys.stderr) return 1 return 0 try: fetch_values(url) except Exception as e: - print >>sys.stderr, "Failed to fetch values: '%s'" % e + print("Failed to fetch values: '%s'" % e, file=sys.stderr) return 1 return 0 |