guest@dotshare [~/groups/wms/i3] $ ls i3status-py-for-Moosic-and-Bars/ | cat

i3status py for Moosic and Bars (scrot)

bziur Nov 29, 2015 (wms/i3)

.i3status.conf(raw, dl)

SCROT

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
general {
    output_format = "i3bar"
    colors = true
    interval = 5
}

order += "wireless _first_"
order += "ethernet _first_"
order += "disk /"
order += "load"
order += "tztime local"

wireless _first_ {
    format_up = "⦳ %quality %ip"
    format_down = "⦳ off"
}

ethernet _first_ {
    format_up = "⦰ %ip (%speed)"
    format_down = "⦰ off"
}

disk "/" {
    format = "⛃ %avail"
}

tztime local {
    format = "%Y.%m.%d %H:%M ⣿"
}

load {
    format = "⚛ %1min"
}

CLICK TO VIEW

x

.i3status.py(raw, dl)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import subprocess
import json

def get_moosic_current():
    """ Geth the current moosic track """
    path = subprocess.check_output(["moosic", "current"])[0:-1]
    if not path:
        return "■"
    tags = subprocess.check_output(["lltag", "--show-tags=artist,title", path])
    try:
        tags = tags.decode()
    except UnicodeDecodeError:
        return "..."
    lines = tags.split('\n')
    artist = lines[1].split("=")[-1]
    title  = lines[2].split("=")[-1]
    return " ".join(["▶",artist,"-",title,"♬"])

def percent_to_float(string):
    """ Converts 037% to 0.37 """
    return float(string.strip('%'))/100

def float_to_bars(string, vertical=False):
    """ Converts 0.37 to bars like ▁ """
    if vertical:
        #      ₁₂₃₄₅₆₇₈
        chars="▁▂▃▄▅▆▇█"
    else:
        #      ₁₂₃₄₅₆₇₈
        chars="▏▎▍▌▋▊▉█"
    scale = 1/8
    real = float(string)
    for i in range(1,8):
        if (scale * i) >= real:
            return chars[i-1] # indexes 0-7
    return chars[-1]; # XXX load isn't a percentage

def print_line(message):
    """ Non-buffered printing to stdout. """
    sys.stdout.write(message + '\n')
    sys.stdout.flush()

def read_line():
    """ Interrupted respecting reader for stdin. """
    # try reading a line, removing any extra whitespace
    try:
        line = sys.stdin.readline().strip()
        # i3status sends EOF, or an empty line
        if not line:
            sys.exit(3)
        return line
    # exit on ctrl-c
    except KeyboardInterrupt:
        sys.exit()

def skip_line():
    print_line(read_line())

if __name__ == '__main__':
    # Skip the first line which contains the version header.
    # The second line contains the start of the infinite array.
    skip_line()
    skip_line()

    while True:
        line, prefix = read_line(), ''
        # ignore comma at start of lines
        if line.startswith(','):
            line, prefix = line[1:], ','

        j = json.loads(line)
        # insert information into the start of the json, but could be anywhere
        # CHANGE THIS LINE TO INSERT SOMETHING ELSE
        j.insert(0, {'full_text' : get_moosic_current(), 'name' : 'moosic'})
        # replace wifi %range and proc load to nice bars
        for item in j:
            if item["name"] == "load":
                parts = item["full_text"].split()
                parts[-1] = float_to_bars(parts[-1], True)
                item["full_text"] = " ".join(parts)
            if item["name"] == "wireless":
                parts = item["full_text"].split()
                for k, val in enumerate(parts):
                    if '%' in val:
                        parts[k] = float_to_bars(percent_to_float(val), True)
                item["full_text"] = " ".join(parts)
        # and echo back new encoded json
        print_line(prefix+json.dumps(j))
 

x

Notes

This is simple i3status python script paired with fitting config.

  • turns load and network signal strength to bars
  • parses moosic current song artist and title (could probably make it more configurable)
  • displays neat icons

Usage:

bar {
    status_command i3status | ~/.i3status.py
    font pango: Gohufont 8
    separator_symbol "⡇"
    ...
}

Requirements:

  • python (3+ should do)
  • gohufont (I use gohufont-powerline)
  • lltag (with depts) // for parsing moosic nam

Known Issues:

  • currently sometimes the song title decoding fails.
  • load isn’t percentage