Modified box.py to call haplaylist shell script

Box.py now calls haplaylist.sh and passes the plist variable. The haplaylist.sh calls a curl command to a home assistant instance running on another machine and passes the playlist variable to an input_text component. Also included is the musiccards.service for systemd to start box.py automatically on boot.
This commit is contained in:
hoveeman
2018-03-25 16:43:55 -04:00
committed by GitHub
parent 7852a100b8
commit 144fd273c8
3 changed files with 24 additions and 31 deletions

35
box.py
View File

@@ -1,34 +1,11 @@
#!/usr/bin/env python
from mpd import MPDClient
#from readtest import *
import re
from CardList import CardList
from Reader import Reader
import sys
def connectMPD():
try:
client = MPDClient() # create client object
client.timeout = 200 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None
print "Connecting..."
client.connect("localhost", 6600)
print "Connected!"
return client
except:
print 'Could not connect to MPD server'
def play(client, plist):
try:
client.stop()
client.clear()
client.add(plist)
if re.search('playlist',plist):
client.shuffle()
client.play()
except:
print 'Could not play playlist %s' % plist
import subprocess
import shlex
reader = Reader()
cardList = CardList()
@@ -42,13 +19,9 @@ while True:
plist = cardList.getPlaylist(card)
print 'Playlist', plist
if plist != '':
client = connectMPD()
if plist=='pause':
client.pause()
else:
play(client, plist)
client.close()
subprocess.check_call( ["./haplaylist.sh %s" % plist], shell=True)
except KeyboardInterrupt:
sys.exit(0)
except:
pass