import psutil
import os
import time
import math

blocks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']

def create_bar(filled):
    if filled > 1:
        low = str(int(filled))
        high = str(int(filled + 1))
        filled = filled - int(filled)
    filled = int(filled * 100)
    if filled < 50:
        color = "green"
    elif filled < 80:
        color = "yellow"
    else:
        color = "red"
    block = math.floor(filled / (100 / 7) + 0.5)
    bar = '#[fg=' + color + ']▕'
    bar += blocks[block]
    bar += '▏'
    if filled >= 100:
        bar += str(filled)
    else:
        bar += "{0:2}%".format(filled)
    bar += '#[fg=default]'
    return bar


while True:
    meminfo = psutil.virtual_memory()
    numcpus = psutil.cpu_count()

    with open(os.path.expanduser("~/.memblock"), "w") as memblock:
        memblock.write(create_bar((meminfo.total - meminfo.available) / meminfo.total))
    with open(os.path.expanduser("~/.cpuutilblock"), "w") as cpuutilblock:
        cpuutilblock.write(create_bar(psutil.cpu_percent() / 100))
    time.sleep(20)

import psutil
import os
import time
import math

blocks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']

def create_bar(filled):
    filled = int(filled * 100)
    if filled < 50:
        color = "green"
    elif filled < 80:
        color = "yellow"
    else:
        color = "red"
    bar = '#[fg=' + color + ']▕'
    if filled < 100:
        block = math.floor(filled / (100 / 7) + 0.5)
        bar += blocks[block]
    else:
        bar += blocks[7]
    bar += '▏'
    if filled >= 100:
        bar += str(filled)
    else:
        bar += "{0:2}%".format(filled)
    bar += '#[fg=default]'
    return bar


while True:
    meminfo = psutil.virtual_memory()
    numcpus = psutil.cpu_count()

    with open(os.path.expanduser("~/.memblock"), "w") as memblock:
        memblock.write(create_bar((meminfo.total - meminfo.available) / meminfo.total))
    with open(os.path.expanduser("~/.cpuutilblock"), "w") as cpuutilblock:
        cpuutilblock.write(create_bar(psutil.cpu_percent() / 100))
    time.sleep(20)

Allow over 100 again for when load becomes available
Allow over 100 again for when load becomes available

  import psutil
  import os
  import time
  import math
  
  blocks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']
  
  def create_bar(filled):
-     if filled > 1:
-         low = str(int(filled))
-         high = str(int(filled + 1))
-         filled = filled - int(filled)
      filled = int(filled * 100)
      if filled < 50:
          color = "green"
      elif filled < 80:
          color = "yellow"
      else:
          color = "red"
-     block = math.floor(filled / (100 / 7) + 0.5)
      bar = '#[fg=' + color + ']▕'
+     if filled < 100:
+         block = math.floor(filled / (100 / 7) + 0.5)
-     bar += blocks[block]
+         bar += blocks[block]
+     else:
+         bar += blocks[7]
      bar += '▏'
      if filled >= 100:
          bar += str(filled)
      else:
          bar += "{0:2}%".format(filled)
      bar += '#[fg=default]'
      return bar
  
  
  while True:
      meminfo = psutil.virtual_memory()
      numcpus = psutil.cpu_count()
  
      with open(os.path.expanduser("~/.memblock"), "w") as memblock:
          memblock.write(create_bar((meminfo.total - meminfo.available) / meminfo.total))
      with open(os.path.expanduser("~/.cpuutilblock"), "w") as cpuutilblock:
          cpuutilblock.write(create_bar(psutil.cpu_percent() / 100))
      time.sleep(20)
  
Allow over 100 again for when load becomes available
## Code Before:
import psutil
import os
import time
import math

blocks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']

def create_bar(filled):
    if filled > 1:
        low = str(int(filled))
        high = str(int(filled + 1))
        filled = filled - int(filled)
    filled = int(filled * 100)
    if filled < 50:
        color = "green"
    elif filled < 80:
        color = "yellow"
    else:
        color = "red"
    block = math.floor(filled / (100 / 7) + 0.5)
    bar = '#[fg=' + color + ']▕'
    bar += blocks[block]
    bar += '▏'
    if filled >= 100:
        bar += str(filled)
    else:
        bar += "{0:2}%".format(filled)
    bar += '#[fg=default]'
    return bar


while True:
    meminfo = psutil.virtual_memory()
    numcpus = psutil.cpu_count()

    with open(os.path.expanduser("~/.memblock"), "w") as memblock:
        memblock.write(create_bar((meminfo.total - meminfo.available) / meminfo.total))
    with open(os.path.expanduser("~/.cpuutilblock"), "w") as cpuutilblock:
        cpuutilblock.write(create_bar(psutil.cpu_percent() / 100))
    time.sleep(20)

## Instruction:
Allow over 100 again for when load becomes available
## Code After:
import psutil
import os
import time
import math

blocks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']

def create_bar(filled):
    filled = int(filled * 100)
    if filled < 50:
        color = "green"
    elif filled < 80:
        color = "yellow"
    else:
        color = "red"
    bar = '#[fg=' + color + ']▕'
    if filled < 100:
        block = math.floor(filled / (100 / 7) + 0.5)
        bar += blocks[block]
    else:
        bar += blocks[7]
    bar += '▏'
    if filled >= 100:
        bar += str(filled)
    else:
        bar += "{0:2}%".format(filled)
    bar += '#[fg=default]'
    return bar


while True:
    meminfo = psutil.virtual_memory()
    numcpus = psutil.cpu_count()

    with open(os.path.expanduser("~/.memblock"), "w") as memblock:
        memblock.write(create_bar((meminfo.total - meminfo.available) / meminfo.total))
    with open(os.path.expanduser("~/.cpuutilblock"), "w") as cpuutilblock:
        cpuutilblock.write(create_bar(psutil.cpu_percent() / 100))
    time.sleep(20)
