Intendation; foodoord_oben - right API™

This commit is contained in:
Bandie 2021-11-13 14:27:33 +01:00
parent 72b2276603
commit ce451daef1
Signed by: Bandie
GPG Key ID: 843D7FA93BA46312
2 changed files with 137 additions and 132 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# vim: ts=2 sw=2 et
import os import os
import stat import stat
@ -14,8 +15,9 @@ from ConfigParser import SafeConfigParser
parser = SafeConfigParser() parser = SafeConfigParser()
parser.read('/etc/foodoord.conf') parser.read('/etc/foodoord.conf')
url = parser.get('door_firstlevel', 'status_url') doorapi = parser.get('doorstatus', 'status_url')
old_api = parser.get('door_firstlevel_old', 'status_url') consumerkey = parser.get('doorstatus', 'key')
consumersecret = parser.get('doorstatus', 'secret')
#Definitions for output #Definitions for output
@ -33,10 +35,16 @@ RED=1
GREEN=2 GREEN=2
ORANGE=3 ORANGE=3
def update_api(locked):
try:
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"aerie\": " + str(locked).lower() + " }' '" + doorapi + "' ")
except:
pass
if __name__ == "__main__": if __name__ == "__main__":
def doorbell(event): def doorbell(event):
if (STATUS): if (STATUS):
pifacedigital.relays[RELAYS_UNLOCK].toggle() pifacedigital.relays[RELAYS_UNLOCK].toggle()
@ -48,8 +56,7 @@ if __name__ == "__main__":
global STATUS global STATUS
STATUS = False STATUS = False
try: try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2) update_api(True)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except: except:
pass pass
@ -66,8 +73,7 @@ if __name__ == "__main__":
os.remove("/var/run/foodoord.pipe") os.remove("/var/run/foodoord.pipe")
try: try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2) update_api(True)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except: except:
pass pass
@ -114,8 +120,7 @@ if __name__ == "__main__":
STATUS = False STATUS = False
try: try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2) update_api(True)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except: except:
pass pass
@ -129,8 +134,7 @@ if __name__ == "__main__":
if (STATUS==False): if (STATUS==False):
try: try:
urllib2.urlopen(url+'&door=aerie&locked=0', timeout=2) update_api(False)
urllib2.urlopen(old_api+'&status=open', timeout=2)
except: except:
pass pass

View File

@ -1,4 +1,5 @@
#! /usr/bin/python #! /usr/bin/python
# vim: ts=2 sw=2 et
import os import os
import stat import stat