Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import telnetlib;
- import time;
- import os;
- import subprocess;
- host='127.0.0.1';
- port='13666';
- data = ""
- tn = telnetlib.Telnet(host, port)
- tn.write("hello\r");
- data += tn.read_until("\n");
- tn.write("screen_add my_screen\n");
- data += tn.read_until("\n");
- tn.write("screen_set my_screen 1 -heartbeat off\n");
- data += tn.read_until("\n");
- tn.write("widget_add my_screen 1 scroller\n");
- data += tn.read_until("\n");
- tn.write("widget_add my_screen 2 scroller\n");
- data += tn.read_until("\n");
- var = 1;
- while var == 1 :
- cmd1 = "mpc | head -1" #gets the currently playing song from mpc
- process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- mpc_song = process.stdout.read().strip()
- cmd2 = "mpc | grep vol | cut -d% -f1 | sed 's/[^0-9]*//g'" #gets the volume level from mpc
- process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- mpc_vol = process.stdout.read().strip()
- cmd3 = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
- process = subprocess.Popen(cmd3, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- mpc_state = process.stdout.read().strip()
- cmd4 = "hostname -I" #gets the current ip of the boombox
- process = subprocess.Popen(cmd4, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- ip_addr = process.stdout.read().strip()
- cmd5 = "netstat -t | grep rfe" #check if a user is connected via airplay
- process = subprocess.Popen(cmd5, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- airplay = process.stdout.read().strip()
- cmd6 = "iwconfig wlan0 | grep Signal | awk '{print $4}' | cut -d= -f2" #check wifi signal strength
- process = subprocess.Popen(cmd6, stdout=subprocess.PIPE , shell=True)
- os.waitpid(process.pid, 0)[1]
- wifi_strength = process.stdout.read().strip()
- if airplay: ##If airplay is in use, pause MPC and display Airplay Mode on LCD else display mpc data as normal
- mpc_pause = "mpc pause"
- process = subprocess.Popen(mpc_pause, stdout=subprocess.PIPE , shell=True)
- tn.write("widget_set my_screen 1 1 1 16 1 m 5 \"Airplay Mode\"\n");
- data += tn.read_until("\n");
- else:
- tn.write("widget_set my_screen 1 1 1 16 1 m 8 \"%s \" \n" % (mpc_song));
- data += tn.read_until("\n");
- tn.write("widget_set my_screen 2 1 2 16 2 m 8 \"Vol:%s %s IP:%s Signal Pwr: %s \"\n" % (mpc_vol,mpc_state,ip_addr,wifi_strength));
- data += tn.read_until("\n");
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement