Пример #1
0
def sendline():
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("localhost", 6600))
    except ConnectionRefusedError:
        time.sleep(1)
        return
    except OSError:
        time.sleep(1)
        return
    try:
        version = sock.recv(2048)
    except InterruptedError:
        pass

    assert version == b"OK MPD 0.19.0\n"

    sock.send(b"currentsong\n")
    currsong = mpd2dict(sock.recv(2048).decode("UTF-8"))

    if currsong == {}:
        return

    sock.send(b"status\n")
    status = mpd2dict(sock.recv(2048).decode("UTF-8"))

    infodict = currsong.copy()
    infodict.update(status)

    artistcolour = "#a1b56c"
    titlecolour = "#ac4142"
    albumcolour = "#6a9fb5"

    if infodict["state"] == "pause":
        titlecolour = darken(titlecolour)
        albumcolour = darken(albumcolour)
        artistcolour = darken(artistcolour)

    block = "<span foreground='{}'>{}</span>"

    for item in ["Artist", "Title", "Album"]:
        if item not in infodict:
            infodict[item] = "Unknown {}".format(item)

    fmline = "{} - {} - {}".format(
        block.format(artistcolour, infodict["Artist"]),
        block.format(titlecolour, infodict["Title"]),
        block.format(albumcolour, infodict["Album"]),
    )

    formatcodes = fmline.replace("&", "&amp;")
    linelib.sendblock(ID, {"full_text": formatcodes, "markup": "pango"})
    linelib.sendPID(ID)
    linelib.waitsig(1)
    click = linelib.getclick(ID).decode("UTF-8")
    if click != "":
        x = json.loads(click)
        if x["button"] == 1:
            sock.send(b"pause\n")
Пример #2
0
def sendline():
    try:
        x = r.get_unread(fetch=True)
    except requests.exceptions.HTTPError:
        #happens when reddit returns a 503. It should come back up soon.
        return
    x = list(x)
    if len(x) > 0:
        linelib.sendblock(ID, {
            "full_text": "[{}]".format(str(len(x))),
            "color": "#ff4500"
        })
    linelib.sendPID(ID)
    linelib.waitsig(5)
Пример #3
0
import signal
import linelib
import subprocess


def handler(x, y):
    pass


signal.signal(signal.SIGUSR1, handler)
signal.signal(signal.SIGALRM, handler)

ID = "ping"

toping = "8.8.8.8"

while True:
    try:
        raw = subprocess.check_output(["ping", "-c1", toping])
        line = raw.decode("UTF8").split("\n")[1]
        time = line.split(" ")[6][5:]
        linelib.sendblock(ID, {"full_text": "{}ms".format(time)})
        linelib.sendPID(ID)
        linelib.waitsig(5)
    except subprocess.CalledProcessError:
        linelib.sendblock(ID, {
            "full_text": "NOT CONNECTED".format(time),
            "color": "#ff0000"
        })
        linelib.waitsig(1)
Пример #4
0
import linelib
import datetime
import signal


def handler(x, y):
    pass


signal.signal(signal.SIGUSR1, handler)
signal.signal(signal.SIGALRM, handler)

while True:
    linelib.sendblock(
        "date",
        {"full_text": datetime.datetime.now().strftime("%Y-%m-%e %H:%M:%S")})
    linelib.sendPID("date")
    linelib.waitsig(1)