document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2.  
  3. import telnetlib;
  4. import time;
  5. import os;
  6. import subprocess;
  7.  
  8. host=\'127.0.0.1\';
  9. port=\'13666\';
  10. data = ""
  11.  
  12.  
  13.  
  14. tn = telnetlib.Telnet(host, port)
  15. tn.write("hello\\r");
  16.  
  17. data += tn.read_until("\\n");
  18. tn.write("screen_add my_screen\\n");
  19. data += tn.read_until("\\n");
  20.  
  21. tn.write("screen_set my_screen 1 -heartbeat off\\n");
  22. data += tn.read_until("\\n");
  23.  
  24. tn.write("widget_add my_screen 1 scroller\\n");
  25. data += tn.read_until("\\n");
  26.  
  27. tn.write("widget_add my_screen 2 scroller\\n");
  28. data += tn.read_until("\\n");
  29.  
  30.  
  31. var = 1;
  32. while var == 1 :
  33.  
  34.   cmd1 = "mpc | head -1"        #gets the currently playing song from mpc
  35.   process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
  36.   os.waitpid(process.pid, 0)[1]
  37.   mpc_song = process.stdout.read().strip()
  38.  
  39.   cmd2 = "mpc | grep vol | cut -d% -f1 | sed \'s/[^0-9]*//g\'"    #gets the volume level from mpc
  40.   process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
  41.   os.waitpid(process.pid, 0)[1]
  42.   mpc_vol = process.stdout.read().strip()
  43.  
  44.   cmd3 = "mpc | head -2 | tail -1 | awk \'{print $1}\'" # gets the player state ie paused playing etc
  45.   process = subprocess.Popen(cmd3, stdout=subprocess.PIPE , shell=True)
  46.   os.waitpid(process.pid, 0)[1]
  47.   mpc_state = process.stdout.read().strip()
  48.  
  49.   cmd4 = "hostname -I"  #gets the current ip of the boombox
  50.   process = subprocess.Popen(cmd4, stdout=subprocess.PIPE , shell=True)
  51.   os.waitpid(process.pid, 0)[1]
  52.   ip_addr = process.stdout.read().strip()
  53.  
  54.   cmd5 = "netstat -t | grep rfe" #check if a user is connected via airplay
  55.   process = subprocess.Popen(cmd5, stdout=subprocess.PIPE , shell=True)
  56.   os.waitpid(process.pid, 0)[1]
  57.   airplay = process.stdout.read().strip()
  58.  
  59.   cmd6 = "iwconfig wlan0 | grep Signal | awk \'{print $4}\' | cut -d= -f2" #check wifi signal strength
  60.   process = subprocess.Popen(cmd6, stdout=subprocess.PIPE , shell=True)
  61.   os.waitpid(process.pid, 0)[1]
  62.   wifi_strength = process.stdout.read().strip()
  63.  
  64.  
  65.   if airplay:  ##If airplay is in use, pause MPC and display Airplay Mode on LCD else display mpc data as normal
  66.     mpc_pause = "mpc pause"
  67.     process = subprocess.Popen(mpc_pause, stdout=subprocess.PIPE , shell=True)
  68.     tn.write("widget_set my_screen 1 1 1 16 1 m 5 \\"Airplay Mode\\"\\n");
  69.     data += tn.read_until("\\n");
  70.   else:
  71.     tn.write("widget_set my_screen 1 1 1 16 1 m 8 \\"%s \\" \\n" % (mpc_song));
  72.     data += tn.read_until("\\n");
  73.  
  74.   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));
  75.   data += tn.read_until("\\n");
  76.   time.sleep(5)
');