#!/usr/bin/env python3
from subprocess import run, PIPE
import re
import spectra
from typing import Tuple
from strict_hint import strict


@strict
def rgb_from_percent(percent: int) -> Tuple[int, int, int]:
    """Get the proper red green and blue values for a given percent."""
    green_value = (percent * 2) / 100 * 255
    red_value = (200 - percent * 2) / 100 * 255
    if green_value > 255:
        green_value = 255
    if red_value > 255:
        red_value = 255
    return (int(red_value), int(green_value), 0)


@strict
def hex_from_rgb(red: int, green: int, blue: int) -> str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = "#"
    assert 0 <= red <= 255, "Color values must be between 0 and 255, got " \
        + str(red)
    assert 0 <= green <= 255, "Color values must be between 0 and 255, got " \
        + str(green)
    assert 0 <= blue <= 255, "Color values must be between 0 and 255, got " \
        + str(blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


battfile    = "/org/freedesktop/UPower/devices/battery_C23B"
batstat     = run(f"upower -i {battfile}", stdout=PIPE, shell=True)
percstr     = ""
for line in batstat.stdout.decode().split("\n"):
    if "state" in line:
        stateline = line
    if "percentage" in line:
        percstr = line
state       = re.sub(r"\s*state:\s*", '', stateline)
perc        = re.search(r"\d\d\d?%", percstr)
percent     = percstr[perc.start():perc.end()].strip('%')
if state == "fully-charged":
    print(state)
    print(state)
else:
    print(state, '-', percent + '%')
    print(state, '-', percent + '%')

print(hex_from_rgb(*rgb_from_percent(int(percent))))
print(spectra.range(
    [spectra.rgb(0xFF, 0, 0), spectra.rgb(0, 0xFF, 0)],
    100
)[percent - 1])

54226541275db4bcbcb401f1da6d934ccd19da64
<mask token>


@strict
def hex_from_rgb(red: int, green: int, blue: int) ->str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = '#'
    assert 0 <= red <= 255, 'Color values must be between 0 and 255, got ' + str(
        red)
    assert 0 <= green <= 255, 'Color values must be between 0 and 255, got ' + str(
        green)
    assert 0 <= blue <= 255, 'Color values must be between 0 and 255, got ' + str(
        blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


<mask token>

<mask token>


@strict
def rgb_from_percent(percent: int) ->Tuple[int, int, int]:
    """Get the proper red green and blue values for a given percent."""
    green_value = percent * 2 / 100 * 255
    red_value = (200 - percent * 2) / 100 * 255
    if green_value > 255:
        green_value = 255
    if red_value > 255:
        red_value = 255
    return int(red_value), int(green_value), 0


@strict
def hex_from_rgb(red: int, green: int, blue: int) ->str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = '#'
    assert 0 <= red <= 255, 'Color values must be between 0 and 255, got ' + str(
        red)
    assert 0 <= green <= 255, 'Color values must be between 0 and 255, got ' + str(
        green)
    assert 0 <= blue <= 255, 'Color values must be between 0 and 255, got ' + str(
        blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


<mask token>
for line in batstat.stdout.decode().split('\n'):
    if 'state' in line:
        stateline = line
    if 'percentage' in line:
        percstr = line
<mask token>
if state == 'fully-charged':
    print(state)
    print(state)
else:
    print(state, '-', percent + '%')
    print(state, '-', percent + '%')
print(hex_from_rgb(*rgb_from_percent(int(percent))))
print(spectra.range([spectra.rgb(255, 0, 0), spectra.rgb(0, 255, 0)], 100)[
    percent - 1])

<mask token>


@strict
def rgb_from_percent(percent: int) ->Tuple[int, int, int]:
    """Get the proper red green and blue values for a given percent."""
    green_value = percent * 2 / 100 * 255
    red_value = (200 - percent * 2) / 100 * 255
    if green_value > 255:
        green_value = 255
    if red_value > 255:
        red_value = 255
    return int(red_value), int(green_value), 0


@strict
def hex_from_rgb(red: int, green: int, blue: int) ->str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = '#'
    assert 0 <= red <= 255, 'Color values must be between 0 and 255, got ' + str(
        red)
    assert 0 <= green <= 255, 'Color values must be between 0 and 255, got ' + str(
        green)
    assert 0 <= blue <= 255, 'Color values must be between 0 and 255, got ' + str(
        blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


battfile = '/org/freedesktop/UPower/devices/battery_C23B'
batstat = run(f'upower -i {battfile}', stdout=PIPE, shell=True)
percstr = ''
for line in batstat.stdout.decode().split('\n'):
    if 'state' in line:
        stateline = line
    if 'percentage' in line:
        percstr = line
state = re.sub('\\s*state:\\s*', '', stateline)
perc = re.search('\\d\\d\\d?%', percstr)
percent = percstr[perc.start():perc.end()].strip('%')
if state == 'fully-charged':
    print(state)
    print(state)
else:
    print(state, '-', percent + '%')
    print(state, '-', percent + '%')
print(hex_from_rgb(*rgb_from_percent(int(percent))))
print(spectra.range([spectra.rgb(255, 0, 0), spectra.rgb(0, 255, 0)], 100)[
    percent - 1])

from subprocess import run, PIPE
import re
import spectra
from typing import Tuple
from strict_hint import strict


@strict
def rgb_from_percent(percent: int) ->Tuple[int, int, int]:
    """Get the proper red green and blue values for a given percent."""
    green_value = percent * 2 / 100 * 255
    red_value = (200 - percent * 2) / 100 * 255
    if green_value > 255:
        green_value = 255
    if red_value > 255:
        red_value = 255
    return int(red_value), int(green_value), 0


@strict
def hex_from_rgb(red: int, green: int, blue: int) ->str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = '#'
    assert 0 <= red <= 255, 'Color values must be between 0 and 255, got ' + str(
        red)
    assert 0 <= green <= 255, 'Color values must be between 0 and 255, got ' + str(
        green)
    assert 0 <= blue <= 255, 'Color values must be between 0 and 255, got ' + str(
        blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


battfile = '/org/freedesktop/UPower/devices/battery_C23B'
batstat = run(f'upower -i {battfile}', stdout=PIPE, shell=True)
percstr = ''
for line in batstat.stdout.decode().split('\n'):
    if 'state' in line:
        stateline = line
    if 'percentage' in line:
        percstr = line
state = re.sub('\\s*state:\\s*', '', stateline)
perc = re.search('\\d\\d\\d?%', percstr)
percent = percstr[perc.start():perc.end()].strip('%')
if state == 'fully-charged':
    print(state)
    print(state)
else:
    print(state, '-', percent + '%')
    print(state, '-', percent + '%')
print(hex_from_rgb(*rgb_from_percent(int(percent))))
print(spectra.range([spectra.rgb(255, 0, 0), spectra.rgb(0, 255, 0)], 100)[
    percent - 1])

#!/usr/bin/env python3
from subprocess import run, PIPE
import re
import spectra
from typing import Tuple
from strict_hint import strict


@strict
def rgb_from_percent(percent: int) -> Tuple[int, int, int]:
    """Get the proper red green and blue values for a given percent."""
    green_value = (percent * 2) / 100 * 255
    red_value = (200 - percent * 2) / 100 * 255
    if green_value > 255:
        green_value = 255
    if red_value > 255:
        red_value = 255
    return (int(red_value), int(green_value), 0)


@strict
def hex_from_rgb(red: int, green: int, blue: int) -> str:
    """Given a red, green, and blue value, retrieve a valid hexcode.

    Example: hex_from_rgb(255, 255, 0) -> #FFFF00
    """
    hexcode = "#"
    assert 0 <= red <= 255, "Color values must be between 0 and 255, got " \
        + str(red)
    assert 0 <= green <= 255, "Color values must be between 0 and 255, got " \
        + str(green)
    assert 0 <= blue <= 255, "Color values must be between 0 and 255, got " \
        + str(blue)
    for color in (red, green, blue):
        if len(hex(color)) == 3:
            hexcode += '0' + hex(color)[-1:].upper()
        else:
            hexcode += hex(color)[-2:].upper()
    return hexcode


battfile    = "/org/freedesktop/UPower/devices/battery_C23B"
batstat     = run(f"upower -i {battfile}", stdout=PIPE, shell=True)
percstr     = ""
for line in batstat.stdout.decode().split("\n"):
    if "state" in line:
        stateline = line
    if "percentage" in line:
        percstr = line
state       = re.sub(r"\s*state:\s*", '', stateline)
perc        = re.search(r"\d\d\d?%", percstr)
percent     = percstr[perc.start():perc.end()].strip('%')
if state == "fully-charged":
    print(state)
    print(state)
else:
    print(state, '-', percent + '%')
    print(state, '-', percent + '%')

print(hex_from_rgb(*rgb_from_percent(int(percent))))
print(spectra.range(
    [spectra.rgb(0xFF, 0, 0), spectra.rgb(0, 0xFF, 0)],
    100
)[percent - 1])
