-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdoorbellserver2.py
More file actions
executable file
·28 lines (24 loc) · 877 Bytes
/
doorbellserver2.py
File metadata and controls
executable file
·28 lines (24 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# Doorbell server 2 (long story) by Gareth Halfacree <freelance@halfacree.co.uk>
import time, socket, subprocess
bashCommand = "sudo -u blacklaw mocp --pause"
bashCommand2 = "mpg321 /home/blacklaw/bellringing.mp3"
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port = 4242
s.bind(('0.0.0.0', port))
s.listen(5)
while True:
try:
print 'Listening for connection.'
c, addr = s.accept()
print 'Connection accepted from', addr
print 'Wakey-wakey!.'
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
process = subprocess.Popen(bashCommand2.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
c.send('Bell rung.\n')
c.close()
except KeyboardInterrupt:
s.close()