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("&", "&") 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")
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)
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)
pass signal.signal(signal.SIGUSR1, handler) signal.signal(signal.SIGALRM, handler) ID = "df" wanted = ["/", "/home/jack/mount/NAS/downloads"] names = {"/": "/", "/home/jack/mount/NAS/downloads": "NAS"} while True: fslines = subprocess.check_output(["df", "-h"]).decode("utf-8").split("\n") fslines = fslines[1:-1] filesystems = [] for line in fslines: fs = fsfromline(line) if fs.mount in wanted: filesystems.append(fs) blocks = [] formatstr = "{}: {}/{}" for item in filesystems: blocks.append(formatstr.format(names[item.mount], item.used, item.total)) linelib.sendblock(ID, {"full_text": " || ".join(blocks)}) linelib.sendPID(ID) linelib.waitsig(1)
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)
import signal import linelib def handler(x, y): pass signal.signal(signal.SIGUSR1, handler) signal.signal(signal.SIGALRM, handler) ID = "template" while True: with open("/proc/loadavg") as f: (min1, min5, min15, tasks, maxpid) = f.read().split(" ") linelib.sendblock(ID, {"full_text": min1}) linelib.sendPID(ID) linelib.waitsig(1)
import signal import linelib import subprocess def handler(x, y): pass signal.signal(signal.SIGUSR1, handler) signal.signal(signal.SIGALRM, handler) ID = "updates" while True: updates = subprocess.check_output(["/usr/bin/pacaur", "-Qua" ]).decode("ASCII").strip().split("\n") linelib.sendblock(ID, {"full_text": str(len(updates))}) linelib.sendPID(ID) linelib.waitsig(1)
import signal import linelib def handler(x, y): pass signal.signal(signal.SIGUSR1, handler) signal.signal(signal.SIGALRM, handler) ID = "template" while True: linelib.sendblock(ID, {"full_text": ""}) linelib.sendPID(ID) linelib.waitsig(1)
import time from datetime import timedelta import linelib while True: with open('/proc/uptime', 'r') as f: uptime_seconds = float(f.readline().split()[0]) uptime_string = timedelta(seconds=uptime_seconds) time.sleep(.01) linelib.sendblock("uptime", {"full_text": str(uptime_string)})