get disk usage by file types

Please use the script to get, what are the file types are there in the given path? and how much of memory they have consumed over there?

## file type usage statistics
import os
def convert_bytes(bytes):
    bytes = float(bytes)
    if bytes >= 1099511627776:
        terabytes = bytes / 1099511627776
        size = '%.2fT' % terabytes
    elif bytes >= 1073741824:
        gigabytes = bytes / 1073741824
        size = '%.2fG' % gigabytes
    elif bytes >= 1048576:
        megabytes = bytes / 1048576
        size = '%.2fM' % megabytes
    elif bytes >= 1024:
        kilobytes = bytes / 1024
        size = '%.2fK' % kilobytes
    else:
        size = '%.2fb' % bytes
    return size
typesizeH = {}
typesize = {}
path = 'C:\\Users\\purushothaman\\Downloads' ## you can change path here
try:
    for root, dirs, files in os.walk(path):
        for file in files:
            prefix, extension = os.path.splitext(file)
            extension = extension.lower()
            if extension not in typesize:
                typesize[extension] = 0
            typesize[extension] += os.stat(root + os.sep + file).st_size
except KeyboardInterrupt:
    pass
 
for key in typesize:
    typesizeH[key] = convert_bytes(typesize[key])
##print str(typesizeH)
types = typesize.keys()
types.sort(cmp=lambda a,b: cmp(typesize[a], typesize<b>), reverse=True)
print "Filetype	Size"
for type in types:
    print "%s	%s" % (type, typesizeH[type])

Note:
path = ‘C:\Users\purushothaman\Downloads’ ## you can change path here
at the above line of code, you can change your path.

Sample Output:

file type usage statistics.PNG

How about make dashboard section based on this? Per customer (category), for example.