# HG changeset patch # User drewp@bigasterisk.com # Date 1555835327 25200 # Node ID a0afc44cec320150f7c8c770431ea9e748aacff6 # Parent 6c5bc38e4676cec3d36583c50eb2e9b9d9f88f90 old event notifier tool. this should be done in reasoning/ now. Ignore-this: 8e4b6aa1dbffb0ec5d4e6239059c74af diff -r 6c5bc38e4676 -r a0afc44cec32 service/frontdooropen.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/frontdooropen.py Sun Apr 21 01:28:47 2019 -0700 @@ -0,0 +1,27 @@ +#!/my/proj/homeauto/service/frontDoorArduino/bin/python +from pymongo import Connection +from dateutil.tz import tzlocal +import restkit, time, datetime +from web.utils import datestr + +c3po = restkit.Resource('http://bang:9040/') +sensor = Connection("bang", 27017, tz_aware=True)['house']['sensor'] + +lastSent = None + +while True: + q = {"name":"frontDoor", "state":"open"} + if lastSent is not None: + q['t'] = {"$gt":lastSent} + + for row in sensor.find(q).sort([('t',-1)]).limit(1): + t = row['t'].astimezone(tzlocal()) + msg = "front door opened at %s" % t.replace(microsecond=0).time().isoformat() + if lastSent is not None: + msg += " (previous was %s)" % datestr(lastSent, datetime.datetime.now(tzlocal())) + for u in ["http://bigasterisk.com/foaf.rdf#drewp", "http://bigasterisk.com/kelsi/foaf.rdf#kelsi"]: + c3po.post(path='', payload=dict(msg=msg, user=u, mode='email')) + + lastSent = row['t'] + + time.sleep(1)