#!/usr/bin/python3


import os

background = '#004953'
background_past = '#002933'
background_next = '#002933'

volume, _, setting = [x[1:-1] for x in os.popen("amixer | grep 'Master' -A 4").read().strip().split('\n')[-1].strip().split(' ')[-3:]]
volume = int(volume[:-1])
if setting == 'on':
    if volume > 0:
        color = ["#ffaf00", "#5faf00"][volume // 51]
        sign = [" ", " "][volume // 51]
    else:
        color = "#888888"
        sign = " "
    text = "{sign} {volume}".format(sign=sign, volume=volume)
else:
    color = "#af0000"
    text = ' '

out = '<span background="{background}" color="{color}"><span color="{background_past}"></span> {text} </span><span background="{background_next}" color="{background}"></span>'

print(out.format(text=text, color=color, background=background, background_next=background_next, background_past=background_past))
