Created
September 15, 2013 00:57
-
-
Save orithena/6567148 to your computer and use it in GitHub Desktop.
(moved to https://github.com/orithena/infotext) Text of mpd/cpu/mem status for display via text-capable xscreensaver (e.g. "Phosphor") --- I use it on my RaspberryPi. Just save it somewhere, edit it to your needs, make it executable and configure xscreensaver to use this program as text source for screensavers like Apple ][, Phosphor, GLText, Fl…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import mpd | |
import pickle | |
def getTimeList(): | |
statFile = file("/proc/stat", "r") | |
timeList = statFile.readline().split(" ")[2:6] | |
statFile.close() | |
for i in range(len(timeList)) : | |
timeList[i] = int(timeList[i]) | |
return timeList | |
def deltaTime() : | |
x = [0,0,0,0] | |
try: | |
f = open('/run/lock/cpuload', 'rd') | |
x = pickle.load(f) | |
f.close() | |
except: pass | |
y = getTimeList() | |
try: | |
f = open('/run/lock/cpuload', 'wb') | |
pickle.dump(y, f) | |
f.close() | |
except: pass | |
for i in range(len(x)) : | |
y[i] -= x[i] | |
return y | |
def cpuload(): | |
dt = deltaTime() | |
return 100 - (dt[len(dt) - 1] * 100.00 / sum(dt)) | |
def load(): | |
r = "" | |
try: | |
r = " ".join(file('/proc/loadavg').readline().split(" ")[0:3]) | |
except: pass | |
return r | |
def meminfo(): | |
return dict([ [ b.strip(":") for b in a if len(b) > 0 and b != 'kB' ] for a in [ l.strip().split(" ") for l in file("/proc/meminfo").readlines() ] ]) | |
print("[cpu %.2f%% load %s]" % (cpuload(), load())) | |
try: | |
mi = meminfo() | |
print("[mem %s free %s cache %s]" % (mi['MemTotal'], mi['MemFree'], mi['Cached']) ) | |
except: pass | |
out = [] | |
mpc = mpd.MPDClient() | |
d = None | |
try: | |
mpc.connect('localhost', 6600) | |
d = dict(mpc.status().items() + mpc.currentsong().items()) | |
mpc.disconnect() | |
except: | |
pass | |
if d is not None and d.has_key("state") and d["state"] == 'play': | |
try: | |
ct = int(float(d["elapsed"])) | |
t = int(d["time"]) | |
out.append("[mpd playing #%s/%s %02d:%02d/%02d:%02d %d%%]" % ( | |
d["song"], | |
d["playlistlength"], | |
ct/60, | |
ct - ((ct/60)*60), | |
t/60, | |
t - ((t/60)*60), | |
int(ct*100/t) | |
)) | |
if d.has_key("title"): out.append(" %s" % d["title"]) | |
if d.has_key("artist"): out.append(" %s" % d["artist"]) | |
if d.has_key("album"): out.append(" %s" % d["album"]) | |
except: | |
pass | |
elif d is not None and d.has_key("state"): | |
out.append("[mpd status: %s]" % d["state"]) | |
else: | |
out.append("[no mpd running at localhost:6600]") | |
if(len(out) < 8): | |
out = [ i for s in [ (a,b) for a,b in zip([ "" for j in xrange(len(out)) ], out) ] for i in s ] | |
out += ["\n"] | |
for l in out: | |
print( unicode(l, 'utf-8', 'ignore').encode("latin-1", 'ignore') ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment