From 666e3d0a0a45675ec91c1b0291299c130d66c503 Mon Sep 17 00:00:00 2001 From: Christian Stade-Schuldt Date: Sat, 4 Nov 2017 17:04:26 +0100 Subject: [PATCH] changes towards python 3 compatibility --- fritzbox_connection_uptime.py | 20 ++++---- fritzbox_cpu_temperature.py | 30 ++++++------ fritzbox_cpu_usage.py | 28 +++++------ fritzbox_memory_usage.py | 42 ++++++++-------- fritzbox_power_consumption.py | 90 +++++++++++++++++------------------ fritzbox_traffic.py | 66 ++++++++++++------------- fritzbox_uptime.py | 22 ++++----- fritzbox_wifi_devices.py | 28 +++++------ 8 files changed, 163 insertions(+), 163 deletions(-) diff --git a/fritzbox_connection_uptime.py b/fritzbox_connection_uptime.py index 6c60765..5742610 100755 --- a/fritzbox_connection_uptime.py +++ b/fritzbox_connection_uptime.py @@ -27,26 +27,26 @@ def print_values(): sys.exit("Couldn't get connection uptime") uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] - print ('uptime.value %.2f' % (int(uptime) / 86400.0)) + print('uptime.value %.2f' % (int(uptime) / 86400.0)) def print_config(): - print "graph_title AVM Fritz!Box Connection Uptime" - print "graph_args --base 1000 -l 0" - print 'graph_vlabel uptime in days' - print "graph_scale no'" - print "graph_category network" - print "uptime.label uptime" - print "uptime.draw AREA" + print("graph_title AVM Fritz!Box Connection Uptime") + print("graph_args --base 1000 -l 0") + print('graph_vlabel uptime in days') + print("graph_scale no'") + print("graph_category network") + print("uptime.label uptime") + print("uptime.draw AREA") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == "__main__": if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print "yes" # Some docs say it'll be called with fetch, some say no arg at all + print("yes") # Some docs say it'll be called with fetch, some say no arg at all elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): try: print_values() diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index 5a9657a..e6aa9c4 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -31,34 +31,34 @@ def get_cpu_temperature(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, (session_id, PAGE)) m = re.search(pattern, data) if m: - print 'temp.value %d' % (int(m.group(1))) + print('temp.value %d' % (int(m.group(1)))) def print_config(): - print "graph_title AVM Fritz!Box CPU temperature" - print "graph_vlabel degrees Celsius" - print "graph_category sensors" - print "graph_order tmp" - print "graph_scale no" - print "temp.label CPU temperature" - print "temp.type GAUGE" - print "temp.graph LINE1" - print "temp.min 0" - print "temp.info Fritzbox CPU temperature" + print("graph_title AVM Fritz!Box CPU temperature") + print("graph_vlabel degrees Celsius") + print("graph_category sensors") + print("graph_order tmp") + print("graph_scale no") + print("temp.label CPU temperature") + print("temp.type GAUGE") + print("temp.graph LINE1") + print("temp.min 0") + print("temp.info Fritzbox CPU temperature") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: diff --git a/fritzbox_cpu_usage.py b/fritzbox_cpu_usage.py index 7ee0efd..c5c0f80 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -31,25 +31,25 @@ def get_cpu_usage(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, session_id, PAGE) m = re.search(pattern, data) if m: - print 'cpu.value %d' % (int(m.group(1))) + print('cpu.value %d' % (int(m.group(1)))) def print_config(): - print "graph_title AVM Fritz!Box CPU usage" - print "graph_vlabel %" - print "graph_category system" - print "graph_order cpu" - print "graph_scale no" - print "cpu.label system" - print "cpu.type GAUGE" - print "cpu.graph AREA" - print "cpu.min 0" - print "cpu.info Fritzbox CPU usage" + print("graph_title AVM Fritz!Box CPU usage") + print("graph_vlabel %") + print("graph_category system") + print("graph_order cpu") + print("graph_scale no") + print("cpu.label system") + print("cpu.type GAUGE") + print("cpu.graph AREA") + print("cpu.min 0") + print("cpu.info Fritzbox CPU usage") if os.environ.get('host_name'): print "host_name " + os.environ['host_name'] @@ -58,7 +58,7 @@ if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index b028d63..e1cdb7c 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -32,41 +32,41 @@ def get_memory_usage(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, session_id, PAGE) matches = re.finditer(pattern, data) if matches: data = zip(USAGE, [m.group(1) for m in matches]) for d in data: - print'%s.value %s' % (d[0], d[1]) + print('%s.value %s' % (d[0], d[1])) def print_config(): - print "graph_title AVM Fritz!Box Memory" - print "graph_vlabel %" - print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100" - print "graph_category system" - print "graph_order strict cache free" - print "graph_info This graph shows what the Fritzbox uses memory for." - print "graph_scale no" - print "strict.label strict" - print "strict.type GAUGE" - print "strict.draw AREA" - print "cache.label cache" - print "cache.type GAUGE" - print "cache.draw STACK" - print "free.label free" - print "free.type GAUGE" - print "free.draw STACK" + print("graph_title AVM Fritz!Box Memory") + print("graph_vlabel %") + print("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100") + print("graph_category system") + print("graph_order strict cache free") + print("graph_info This graph shows what the Fritzbox uses memory for.") + print("graph_scale no") + print("strict.label strict") + print("strict.type GAUGE") + print("strict.draw AREA") + print("cache.label cache") + print("cache.type GAUGE") + print("cache.draw STACK") + print("free.label free") + print("free.type GAUGE") + print("free.draw STACK") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 9256994..38d09ee 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -32,65 +32,65 @@ def get_power_consumption(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, session_id, PAGE) matches = re.finditer(pattern, data) if matches: data = zip(DEVICES, [m.group(4) for m in matches]) for d in data: - print'%s.value %s' % (d[0], d[1]) + print('%s.value %s' % (d[0], d[1])) def print_config(): - print "graph_title AVM Fritz!Box Power Consumption" - print "graph_vlabel %" - print "graph_category system" - print "graph_order system cpu wifi dsl ab usb" - print "system.label system" - print "system.type GAUGE" - print "system.graph LINE12" - print "system.min 0" - print "system.max 100" - print "system.info Fritzbox overall power consumption" - print "cpu.label cpu" - print "cpu.type GAUGE" - print "cpu.graph LINE1" - print "cpu.min 0" - print "cpu.max 100" - print "cpu.info Fritzbox central processor power consumption" - print "wifi.label wifi" - print "wifi.type GAUGE" - print "wifi.graph LINE1" - print "wifi.min 0" - print "wifi.max 100" - print "wifi.info Fritzbox wifi power consumption" - print "dsl.label dsl" - print "dsl.type GAUGE" - print "dsl.graph LINE1" - print "dsl.min 0" - print "dsl.max 100" - print "dsl.info Fritzbox dsl power consumption" - print "ab.label ab" - print "ab.type GAUGE" - print "ab.graph LINE1" - print "ab.min 0" - print "ab.max 100" - print "ab.info Fritzbox analog phone ports power consumption" - print "usb.label usb" - print "usb.type GAUGE" - print "usb.graph LINE1" - print "usb.min 0" - print "usb.max 100" - print "usb.info Fritzbox usb devices power consumption" + print("graph_title AVM Fritz!Box Power Consumption") + print("graph_vlabel %") + print("graph_category system") + print("graph_order system cpu wifi dsl ab usb") + print("system.label system") + print("system.type GAUGE") + print("system.graph LINE12") + print("system.min 0") + print("system.max 100") + print("system.info Fritzbox overall power consumption") + print("cpu.label cpu") + print("cpu.type GAUGE") + print("cpu.graph LINE1") + print("cpu.min 0") + print("cpu.max 100") + print("cpu.info Fritzbox central processor power consumption") + print("wifi.label wifi") + print("wifi.type GAUGE") + print("wifi.graph LINE1") + print("wifi.min 0") + print("wifi.max 100") + print("wifi.info Fritzbox wifi power consumption") + print("dsl.label dsl") + print("dsl.type GAUGE") + print("dsl.graph LINE1") + print("dsl.min 0") + print("dsl.max 100") + print("dsl.info Fritzbox dsl power consumption") + print("ab.label ab") + print("ab.type GAUGE") + print("ab.graph LINE1") + print("ab.min 0") + print("ab.max 100") + print("ab.info Fritzbox analog phone ports power consumption") + print("usb.label usb") + print("usb.type GAUGE") + print("usb.graph LINE1") + print("usb.min 0") + print("usb.max 100") + print("usb.info Fritzbox usb devices power consumption") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: diff --git a/fritzbox_traffic.py b/fritzbox_traffic.py index d0c58cf..25ccb24 100755 --- a/fritzbox_traffic.py +++ b/fritzbox_traffic.py @@ -27,59 +27,59 @@ def print_values(): sys.exit("Couldn't get WAN traffic") down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] - print ('down.value %d' % down_traffic) + print('down.value %d' % down_traffic) up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent'] - print ('up.value %d' % up_traffic) + print('up.value %d' % up_traffic) if not os.environ.get('traffic_remove_max'): max_down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ 'NewLayer1DownstreamMaxBitRate'] - print ('maxdown.value %d' % max_down_traffic) + print('maxdown.value %d' % max_down_traffic) max_up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ 'NewLayer1UpstreamMaxBitRate'] - print ('maxup.value %d' % max_up_traffic) + print('maxup.value %d' % max_up_traffic) def print_config(): - print "graph_title AVM Fritz!Box WAN traffic" - print "graph_args --base 1000" - print "graph_vlabel bits in (-) / out (+) per \${graph_period}" - print "graph_category network" - print "graph_order down up maxdown maxup" - print "down.label received" - print "down.type DERIVE" - print "down.graph no" - print "down.cdef down,8,*" - print "down.min 0" - print "down.max 1000000000" - print "up.label bps" - print "up.type DERIVE" - print "up.draw AREA" - print "up.cdef up,8,*" - print "up.min 0" - print "up.max 1000000000" - print "up.negative down" - print "up.info Traffic of the WAN interface." + print("graph_title AVM Fritz!Box WAN traffic") + print("graph_args --base 1000") + print("graph_vlabel bits in (-) / out (+) per \${graph_period}") + print("graph_category network") + print("graph_order down up maxdown maxup") + print("down.label received") + print("down.type DERIVE") + print("down.graph no") + print("down.cdef down,8,*") + print("down.min 0") + print("down.max 1000000000") + print("up.label bps") + print("up.type DERIVE") + print("up.draw AREA") + print("up.cdef up,8,*") + print("up.min 0") + print("up.max 1000000000") + print("up.negative down") + print("up.info Traffic of the WAN interface.") if not os.environ.get('traffic_remove_max'): - print "maxdown.label received" - print "maxdown.type GAUGE" - print "maxdown.graph no" - print "maxup.label MAX" - print "maxup.type GAUGE" - print "maxup.negative maxdown" - print "maxup.draw LINE1" - print "maxup.info Maximum speed of the WAN interface." + print("maxdown.label received") + print("maxdown.type GAUGE") + print("maxdown.graph no") + print("maxup.label MAX") + print("maxup.type GAUGE") + print("maxup.negative maxdown") + print("maxup.draw LINE1") + print("maxup.info Maximum speed of the WAN interface.") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == "__main__": if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print "yes" # Some docs say it'll be called with fetch, some say no arg at all + print("yes") # Some docs say it'll be called with fetch, some say no arg at all elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): try: print_values() diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index 28c9c48..c08c898 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -39,8 +39,8 @@ def get_uptime(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, session_id, PAGE) matches = re.finditer(pattern, data) if matches: hours = 0.0 @@ -56,22 +56,22 @@ def get_uptime(): def print_config(): - print "graph_title AVM Fritz!Box Uptime" - print "graph_args --base 1000 -l 0" - print 'graph_vlabel uptime in days' - print "graph_scale no'" - print "graph_category system" - print "uptime.label uptime" - print "uptime.draw AREA" + print("graph_title AVM Fritz!Box Uptime") + print("graph_args --base 1000 -l 0") + print('graph_vlabel uptime in days') + print("graph_scale no'") + print("graph_category system") + print("uptime.label uptime") + print("uptime.draw AREA") if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index dd6bce5..b2408da 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -35,33 +35,33 @@ def get_connected_wifi_devices(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) - data = fh.get_page(server, sid, PAGE) + session_id = fh.get_session_id(server, password) + data = fh.get_page_content(server, session_id, PAGE) m = re.search(pattern, data) if m: connected_devices = int(m.group(1)) - print 'wifi.value %d' % connected_devices + print('wifi.value %d' % connected_devices) def print_config(): - print 'graph_title AVM Fritz!Box Connected Wifi Devices' - print 'graph_vlabel Number of devices' - print 'graph_args --base 1000' - print 'graph_category network' - print 'graph_order wifi' - print 'wifi.label Wifi Connections on 2.4 & 5 Ghz' - print 'wifi.type GAUGE' - print 'wifi.graph LINE1' - print 'wifi.info Wifi Connections on 2.4 & 5 Ghz' + print('graph_title AVM Fritz!Box Connected Wifi Devices') + print('graph_vlabel Number of devices') + print('graph_args --base 1000') + print('graph_category network') + print('graph_order wifi') + print('wifi.label Wifi Connections on 2.4 & 5 Ghz') + print('wifi.type GAUGE') + print('wifi.graph LINE1') + print('wifi.info Wifi Connections on 2.4 & 5 Ghz') if os.environ.get('host_name'): - print "host_name " + os.environ['host_name'] + print("host_name " + os.environ['host_name']) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'config': print_config() elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': # Some docs say it'll be called with fetch, some say no arg at all try: