Compare commits

..

1 Commits

Author SHA1 Message Date
T
e2e5878630 Add API v2 2024-07-04 23:03:35 +02:00
5 changed files with 73 additions and 11 deletions

View File

@ -1,3 +1,3 @@
#!/bin/bash
VERSION=3.1.0
VERSION=3.2.0
dpkg-deb --root-owner-group -b debian "foodoord_${VERSION}_all.deb"

View File

@ -1,5 +1,5 @@
Package: foodoord
Version: 3.0.4
Version: 3.2.0
Maintainer: Bandie <bandie@chaospott.de>
Architecture: all
Description: Control the doors of the club, ja!

View File

@ -2,3 +2,8 @@
status_url =
key =
secret =
[doorstatusv2]
status_url =
key =
secret =

View File

@ -10,6 +10,7 @@ import subprocess
import sys
import time
from configparser import ConfigParser
from dataclasses import dataclass
import pifacedigitalio
@ -32,18 +33,46 @@ ORANGE = 3
parser = ConfigParser()
parser.read('/etc/foodoord.conf')
DOORAPI = parser.get('doorstatus', 'status_url')
CONSUMERKEY = parser.get('doorstatus', 'key')
CONSUMERSECRET = parser.get('doorstatus', 'secret')
@dataclass
class API:
api_url: str
consumer_key: str
consumer_secret: str
APIv1 = API(
parser.get('doorstatus', 'status_url'),
parser.get('doorstatus', 'key'),
parser.get('doorstatus', 'secret'),
)
APIv2 = API(
parser.get('doorstatusv2', 'status_url'),
parser.get('doorstatusv2', 'key'),
parser.get('doorstatusv2', 'secret'),
)
def update_api(locked):
try:
# API v1
subprocess.check_call([
"/usr/bin/curl", "-XPOST",
"--header", "Content-Type: application/json",
"--data",
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "aerie": locked})
json.dumps({"consumer_key": APIv1.consumer_key, "consumer_secret": APIv1.consumer_secret, "aerie": locked}),
APIv1.api_url
])
except:
pass
try:
# API v2
subprocess.check_call([
"/usr/bin/curl", "-XPOST",
"--header", "Content-Type: application/json",
"--data",
json.dumps({"consumer_key": APIv2.consumer_key, "consumer_secret": APIv2.consumer_secret, "aerie": locked}),
APIv2.api_url
])
except:
pass

View File

@ -8,6 +8,7 @@ import stat
import subprocess
import time
from configparser import ConfigParser
from dataclasses import dataclass
import RPi.GPIO as gpio
@ -31,9 +32,24 @@ ORANGE = 3
parser = ConfigParser()
parser.read('/etc/foodoord.conf')
DOORAPI = parser.get('doorstatus', 'status_url')
CONSUMERKEY = parser.get('doorstatus', 'key')
CONSUMERSECRET = parser.get('doorstatus', 'secret')
@dataclass
class API:
api_url: str
consumer_key: str
consumer_secret: str
APIv1 = API(
parser.get('doorstatus', 'status_url'),
parser.get('doorstatus', 'key'),
parser.get('doorstatus', 'secret'),
)
APIv2 = API(
parser.get('doorstatusv2', 'status_url'),
parser.get('doorstatusv2', 'key'),
parser.get('doorstatusv2', 'secret'),
)
def write_state(state):
@ -46,12 +62,24 @@ def write_state(state):
def update_api(locked):
try:
# API v1
subprocess.check_call([
"/usr/bin/curl", "-XPOST",
"--header", "Content-Type: application/json",
"--data",
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "cellar": locked}),
DOORAPI
json.dumps({"consumer_key": APIv1.consumer_key, "consumer_secret": APIv1.consumer_secret, "cellar": locked}),
APIv1.api_url
])
except:
pass
try:
# API v2
subprocess.check_call([
"/usr/bin/curl", "-XPOST",
"--header", "Content-Type: application/json",
"--data",
json.dumps({"consumer_key": APIv2.consumer_key, "consumer_secret": APIv2.consumer_secret, "cellar": locked}),
APIv2.api_url
])
except:
pass