Skip to content

Instantly share code, notes, and snippets.

@kernelkaribou
Forked from cbattlegear/bandwidth.py
Last active August 31, 2017 17:28
Show Gist options
  • Save kernelkaribou/6d008f8739d32de645a04ea533824afb to your computer and use it in GitHub Desktop.
Save kernelkaribou/6d008f8739d32de645a04ea533824afb to your computer and use it in GitHub Desktop.
Quick Bandwidth Format function
#Formatting of data sent in bytes to label in largest size
def format_data_type(i, type):
loop = 0
current_num = i
last_num = 0
if type == "net":
label = ["Bps", "KBps", "MBps", "GBps"]
if type == "size":
label = ["B", "KB", "MB", "GB", "TB"]
while(True):
last_num = current_num
current_num = current_num/1024.0
if(current_num < 1):
return '{0:0.0f}{1}'.format(last_num, label[loop])
loop = loop + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment