Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@insom
Created August 18, 2011 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insom/1154344 to your computer and use it in GitHub Desktop.
Save insom/1154344 to your computer and use it in GitHub Desktop.
Turn down MPD when the Avaya phone system detects a call
#!/usr/bin/python
import re
import os
import time
import mpdclient
SERVER = '192.168.1.7'
re_ = re.compile(r'''CALL: [^ ]+ State=. Cut=. Music=... Aend="([^"]+)" [^ ]+ Bend="([^"]+)" (.*) CalledNum=([^ ]+) [^ ]+ CallingNum= ?([^ ]+)''')
upstairs = ['150', '170', '171', '172', '152', '225', '228', '280', '287', '285', '221', '223', '283', '291', '286', '292', '226']
highgain = 80
lowgain = 60
upcount = 0
def up():
c = mpdclient.MpdController(SERVER, 6600)
c.volume(highgain)
print "Volume Up"
def down():
c = mpdclient.MpdController(SERVER, 6600)
c.volume(lowgain)
print "Volume Down"
def next():
c = mpdclient.MpdController(SERVER, 6600)
c.next()
print "Next"
def prev():
c = mpdclient.MpdController(SERVER, 6600)
c.prev()
print "Prev"
def pause():
c = mpdclient.MpdController(SERVER, 6600)
c.pause()
print "Pause"
ison = False
pausecount = 0
playcount = 0
nextcount = 0
pausepress = prevpress = nextpress = False
down()
while 1:
pausepress2 = prevpress2 = nextpress2 = False
z = open('cs02').read()
ilist = re_.findall(z)
onnow = False
for item in ilist:
if(item[3] == '000'):
pausepress2 = True
if(item[3] == '004'):
prevpress2 = True
if(item[3] == '006'):
nextpress2 = True
if(item[3] == '000') and not pausepress:
pause()
pausepress = True
if(item[3] == '004') and not prevpress:
prev()
prevpress = True
if(item[3] == '006') and not nextpress:
next()
nextpress = True
if pausepress2 or nextpress2 or prevpress2: continue
if (item[3] in upstairs) or (item[4] in upstairs):
onnow = True
if not pausepress2: pausepress = False
if not nextpress2: nextpress = False
if not prevpress2: prevpress = False
try:
if onnow and not ison:
ison = True
upcount = 0
down()
if (not onnow) and ison:
ison = False
if not ison:
upcount = upcount + 1
if upcount == 2:
up()
except:
pass
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment