multiplatform build

This commit is contained in:
2024-06-29 03:32:54 +02:00
parent 345666cb2e
commit 5029e46359
11 changed files with 235 additions and 38 deletions

View File

@@ -1,4 +1,10 @@
#!/bin/sh
python3.12 api_endpoints.py &
env > .env
if [ "$API" = true ]; then
python3.12 api_endpoints.py &
sleep 1
fi
sudo python3.12 main.py

View File

@@ -1,6 +1,5 @@
pyyaml
bs4
lxml
requests
flask
flask_cors

View File

@@ -49,7 +49,7 @@ def cleanup():
devices = []
def start_discovery(timeout=20.0):
def start_discovery(timeout=20):
cleanup()
global devices
print(f'Start discovery with timout {timeout}s...')

16
python/src/load_env.py Normal file
View File

@@ -0,0 +1,16 @@
# This is a quick and dirty hack since the ENVs from the docker run command won't show up in the main.py
# I echo the output from the env command of a .env file, read and load it here into the os.environ.
# https://stackoverflow.com/questions/78684481/python-wont-find-the-env-in-my-docker-container
import os
def load_env():
if 'DOCKER' not in os.listdir('.'): return False
with open(file='.env', mode='r') as file: ENV = file.readlines()
for env in ENV:
env = env.strip()
key, value = env.split('=')
os.environ[key] = value
return True

View File

@@ -3,8 +3,9 @@ from log_data import log_to_json
from discovery import start_discovery
def start_loop(interval=60):
def start_loop(interval=40, timeout=20):
print(f"Starting loop with interval {interval}s")
while True:
devices = start_discovery()
devices = start_discovery(timeout=timeout)
log_to_json(devices)
sleep(interval)

View File

@@ -1,9 +1,25 @@
import os
from discovery import start_discovery
from log_data import log_to_json
from loop import start_loop
from load_env import load_env
DOCKER = load_env()
INTERVAL = 40
TIMEOUT = 20
# devices = start_discovery()
# log_to_json(devices)
if DOCKER:
print("Running in docker")
interval = os.getenv('LOOP')
timeout = os.getenv('TIMEOUT')
start_loop()
try:INTERVAL = int(interval)
except:pass
try:TIMEOUT = int(timeout)
except:pass
start_loop(INTERVAL, TIMEOUT)
else:
start_loop(interval=40)