From 51f72b53d686e4f6f6fcd83356d0bcb920411487 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 2 Oct 2012 23:56:08 +0200 Subject: Add doorwatch script --- doorwatch.py | 37 +++++++++++++++++++++++++++++++++++++ doorwatch.wav | Bin 0 -> 26014 bytes doorwatch.wav.txt | 3 +++ 3 files changed, 40 insertions(+) create mode 100644 doorwatch.py create mode 100644 doorwatch.wav create mode 100644 doorwatch.wav.txt diff --git a/doorwatch.py b/doorwatch.py new file mode 100644 index 0000000..c88ac6a --- /dev/null +++ b/doorwatch.py @@ -0,0 +1,37 @@ +# This program plays a "little" sound when the door +# is opened. This is helpful e.g. when sitting back +# in the smokers lounge but wanting the door to be +# unlocked. + +import subprocess +import os +import urllib +import json +import sys +import time + +if __name__ == '__main__': + workdir = os.path.realpath(os.path.dirname(__file__)) + was_closed = False # Don't ding at startup + + while True: + time.sleep(1) + + try: + r = None + r = urllib.urlopen('http://172.22.83.5/subcan.json') + data = json.loads(r.read()) + except Exception: + sys.excepthook(*sys.exc_info()) + continue + finally: + if r is not None: + r.close() + + closed = data['door.left']['value'] + if was_closed and not closed: + print "Door has been opened!" + subprocess.call(['paplay', os.path.join(workdir, 'doorwatch.wav')]) + if not was_closed and closed: + print "Door has been closed." + was_closed = closed diff --git a/doorwatch.wav b/doorwatch.wav new file mode 100644 index 0000000..c610d84 Binary files /dev/null and b/doorwatch.wav differ diff --git a/doorwatch.wav.txt b/doorwatch.wav.txt new file mode 100644 index 0000000..955ff32 --- /dev/null +++ b/doorwatch.wav.txt @@ -0,0 +1,3 @@ +This sound is created from "Mandatory Evacuation" by Brandon which is licensed under CC-Attribution 3.0 + +It was downloaded from http://soundbible.com/1911-Mandatory-Evacuation.html on 2012-10-02 -- cgit v1.2.1