ScAlAn

Python get disk free space in MB and display it on image

Task: Get disk free space in MB and display it on my clock’s screen

Implementation:

    # Disk info
    hdd = psutil.disk_usage('/')
    #print ("Total: %d MB" % int(hdd.total / (1024.0 ** 2)))
    #print ("Used: %d MB" % int(hdd.used / (1024.0 ** 2)))
    #print ("Free: %d MB" % int(hdd.free / (1024.0 ** 2)))
    text = "Free: " + str(int(hdd.free / (1024.0 ** 2))) + " MB"
    font = ImageFont.truetype('./freefont/FreeMonoBold.ttf', 22)
    img_txt = Image.new('L', font.getsize(text), 255)
    draw_txt = ImageDraw.Draw(img_txt)
    draw_txt.text((0, 0), text, font = font, fill = 0)
    t = img_txt.rotate(90, expand=1)
    image.paste(t, (155, 5))

Result you can see on this post image (fourth line).

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *

  +  2  =  9