From d84aaeec53aa0bde29e593327ffc0ee8eeffc4e6 Mon Sep 17 00:00:00 2001 From: Vincent Boiteau-Robert Date: Wed, 31 Aug 2016 11:40:07 -0400 Subject: [PATCH 1/3] Fixing the commandline script --- api.py | 10 +++++++--- netusage.py | 18 +++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/api.py b/api.py index 57d9d1a..48bc2c7 100644 --- a/api.py +++ b/api.py @@ -4,7 +4,7 @@ import time import datetime -def getData(phase,room,month): +def getDataObject(phase,room,month): regexRowUsage = '(.*)(.*)(.*)(.*)' regexUsage = 'Total combiné:(.*)' @@ -56,5 +56,9 @@ def getData(phase,room,month): data['left']=left data['maximum']=maximum - dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None - return json.dumps(data,default=dthandler) \ No newline at end of file + return data + +def getData(phase,room,month): + data = getDataObject(phase,room,month) + dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None + return json.dumps(data,default=dthandler) \ No newline at end of file diff --git a/netusage.py b/netusage.py index 1ba7793..5ca216a 100644 --- a/netusage.py +++ b/netusage.py @@ -9,6 +9,7 @@ import sys from datetime import datetime import api +import simplejson as json def getUsage(type,phase,room): """ type - percent -> percentage of your bandwidth used @@ -19,16 +20,19 @@ def getUsage(type,phase,room): room must be an existing room in the block """ - return api.getData(phase,room,datetime.now().month) - + dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None + data = api.getDataObject(phase,room,datetime.now().month) + pct = (data["maximum"]-data["left"])*100/data["maximum"] if type == "percent": return "{:0.2f}%".format(pct) if type == "left": - return "{:0.2f}GB".format(left) - if type =="usage": - return "{:0.2f}GB".format(usage/1024) - if type =="all": - return "Used :\t\t{:0.2f}GB ({:0.2f}%)\nLeft :\t\t{:0.2f}GB ({:0.2f}%)\nTotal :\t\t{:0.2f}GB".format(usage/1024,pct,left,100-pct,max/1024) + return "{:0.2f}GB".format(data["left"]) + if type == "usage": + return "{:0.2f}GB".format(data["usage"]/1024) + if type == "json": + return api.getData(phase,room,datetime.now().month) + if type =="all": + return "Used :\t\t{:0.2f}GB ({:0.2f}%)\nLeft :\t\t{:0.2f}GB ({:0.2f}%)\nTotal :\t\t{:0.2f}GB".format(data["usage"]/1024,pct,data["left"],100-pct,data["maximum"]/1024) raise Exception('Must choose between "percent" and "left" ') From ce5d38c250b7e5ba81fd3ccba3aec0fddb69567e Mon Sep 17 00:00:00 2001 From: Vincent Boiteau-Robert Date: Wed, 31 Aug 2016 11:42:52 -0400 Subject: [PATCH 2/3] Remove unused import --- netusage.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/netusage.py b/netusage.py index 5ca216a..f06f5f3 100644 --- a/netusage.py +++ b/netusage.py @@ -9,7 +9,6 @@ import sys from datetime import datetime import api -import simplejson as json def getUsage(type,phase,room): """ type - percent -> percentage of your bandwidth used @@ -20,7 +19,6 @@ def getUsage(type,phase,room): room must be an existing room in the block """ - dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None data = api.getDataObject(phase,room,datetime.now().month) pct = (data["maximum"]-data["left"])*100/data["maximum"] if type == "percent": From 02b684c9f654514aa601e15c3b1d04857c52ae2b Mon Sep 17 00:00:00 2001 From: Vincent Boiteau-Robert Date: Wed, 31 Aug 2016 11:46:25 -0400 Subject: [PATCH 3/3] Fix some size --- netusage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netusage.py b/netusage.py index f06f5f3..fdddc9e 100644 --- a/netusage.py +++ b/netusage.py @@ -26,11 +26,11 @@ def getUsage(type,phase,room): if type == "left": return "{:0.2f}GB".format(data["left"]) if type == "usage": - return "{:0.2f}GB".format(data["usage"]/1024) + return "{:0.2f}GB".format(data["usage"]) if type == "json": return api.getData(phase,room,datetime.now().month) if type =="all": - return "Used :\t\t{:0.2f}GB ({:0.2f}%)\nLeft :\t\t{:0.2f}GB ({:0.2f}%)\nTotal :\t\t{:0.2f}GB".format(data["usage"]/1024,pct,data["left"],100-pct,data["maximum"]/1024) + return "Used :\t\t{:0.2f}GB ({:0.2f}%)\nLeft :\t\t{:0.2f}GB ({:0.2f}%)\nTotal :\t\t{:0.2f}GB".format(data["usage"],pct,data["left"],100-pct,data["maximum"]) raise Exception('Must choose between "percent" and "left" ')