fix up some mess
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
env > .env
|
||||
|
||||
if [ "$API" = true ]; then
|
||||
python3.12 api_endpoints.py &
|
||||
sleep 1
|
||||
python3.12 api_endpoints.py &
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
sudo python3.12 main.py
|
||||
python3.12 main.py
|
||||
@@ -1,3 +1,4 @@
|
||||
bluepy
|
||||
pyyaml
|
||||
bs4
|
||||
requests
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# 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
|
||||
@@ -4,6 +4,8 @@ import json
|
||||
from data_class import Data
|
||||
from devices import Device
|
||||
|
||||
DEBUG = True if os.getenv('DEBUG') == 'true' else False
|
||||
|
||||
|
||||
def log_to_json(devices):
|
||||
workdir, filename = os.path.split(os.path.abspath(__file__))
|
||||
@@ -13,7 +15,7 @@ def log_to_json(devices):
|
||||
data_obj: Data
|
||||
from_config: Device
|
||||
file_name = f'{workdir}/data/{str(data_obj.mac).replace(":", "-")}.json'
|
||||
print(file_name)
|
||||
print(file_name) if DEBUG else {}
|
||||
|
||||
try:
|
||||
with open(file_name, 'r') as file: data = json.load(file)
|
||||
|
||||
@@ -2,16 +2,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
|
||||
DOCKER = True if os.getenv('DOCKER') == 'true' else False
|
||||
DEBUG = True if os.getenv('DEBUG') == 'true' else False
|
||||
interval = os.getenv('LOOP')
|
||||
timeout = os.getenv('TIMEOUT')
|
||||
|
||||
if DEBUG:
|
||||
print(f"INTERVAL: {INTERVAL}")
|
||||
print(f"TIMEOUT: {TIMEOUT}")
|
||||
print(f"interval: {interval}")
|
||||
print(f"timeout: {timeout}")
|
||||
print(f"DOCKER: {DOCKER}")
|
||||
print(f"DEBUG: {DEBUG}")
|
||||
print("")
|
||||
|
||||
if DOCKER:
|
||||
print("Running in docker")
|
||||
interval = os.getenv('LOOP')
|
||||
timeout = os.getenv('TIMEOUT')
|
||||
|
||||
try:INTERVAL = int(interval)
|
||||
except:pass
|
||||
@@ -19,7 +28,8 @@ if DOCKER:
|
||||
try:TIMEOUT = int(timeout)
|
||||
except:pass
|
||||
|
||||
start_loop(INTERVAL, TIMEOUT)
|
||||
if interval is None: log_to_json(start_discovery(timeout=TIMEOUT))
|
||||
else:start_loop(INTERVAL, TIMEOUT)
|
||||
|
||||
else:
|
||||
start_loop(interval=40)
|
||||
|
||||
Reference in New Issue
Block a user