From 99fd9b454c1bd62c1faf30f2c884a7746df511e0 Mon Sep 17 00:00:00 2001 From: 12nick12 Date: Wed, 8 Nov 2017 09:56:25 -0500 Subject: [PATCH] Create plexpy_bw.py --- plexpy_bw.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 plexpy_bw.py diff --git a/plexpy_bw.py b/plexpy_bw.py new file mode 100644 index 0000000..61a8d5b --- /dev/null +++ b/plexpy_bw.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# This reports the total bandwidth used. +import json +import requests +import math + +host = '' +api_key = '' +url_base = 'not including slashes' +ssl = 'true/false' + +if ssl == 'true': + http = 'https' +if ssl == 'false': + http = 'http' + +url = http + "://" + host + "/" + url_base + "/api/v2?apikey=" + api_key + "&cmd=get_activity" + +requests.packages.urllib3.disable_warnings() + +response = requests.get(url, verify=False) + +json_input = response.text + +decoded = json.loads(json_input) + +stream_count = decoded['response']['data']['stream_count'] +stream_count = int(stream_count) +bandwidthTotal = 0 + +for i in range(0, stream_count): + bandwidth = decoded['response']['data']['sessions'][i]['bandwidth'] + bandwidthTotal = float(bandwidthTotal) + float(bandwidth) / 1024 + +print("%.2f" % bandwidthTotal)