Skip to content

Commit

Permalink
Add in JSON path as env
Browse files Browse the repository at this point in the history
  • Loading branch information
mchadwick-iqt authored Jun 14, 2024
1 parent 01e5b43 commit 49cd93b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions dump1090-json.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PROJECT_NAME=skyscan
HOSTNAME=skyscan-011
DUMP1090_HOST=piaware
DUMP1090_HTTP_PORT=8080
JSON_PATH=/skyaware/data/aircraft.json
ADS_B_JSON_TOPIC=/${PROJECT_NAME}/${HOSTNAME}/ADS-B/edgetech-dump1090-json/JSON
CONTINUE_ON_EXCEPTION=False
LOG_LEVEL=DEBUG
7 changes: 6 additions & 1 deletion dump1090-json/dump1090-json_pub_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
self,
dump1090_host: str,
dump1090_http_port: str,
json_path: str,
update_time: float,
ads_b_json_topic: str,
ground_level: float,
Expand All @@ -42,6 +43,7 @@ def __init__(
Args:
dump1090_host (str): Host IP of the dump1090 system
dump1090_port (str): Host port of the dump1090 socket
json_path (str): URL path to JSON file
update_time (float): Duration between dump1090 polls
ads_b_json_topic (str): MQTT topic to publish the data from
the port to. Specified via docker-compose.
Expand All @@ -52,6 +54,7 @@ def __init__(
super().__init__(**kwargs)
self.dump1090_host = dump1090_host
self.dump1090_http_port = dump1090_http_port
self.json_path = json_path
self.update_time = update_time
self.ads_b_json_topic = ads_b_json_topic
self.ground_level = ground_level
Expand All @@ -67,6 +70,7 @@ def __init__(
f"""Dump1090PubSub initialized with parameters:
dump1090_host = {dump1090_host}
dump1090_http_port = {dump1090_http_port}
json_path = {json_path}
ground_level = {ground_level}
ads_b_json_topic = {ads_b_json_topic}
continue_on_exception = {continue_on_exception}
Expand Down Expand Up @@ -106,7 +110,7 @@ def _process_response(self) -> None:

request_start = time()
# Get and load the response from the endpoint
url = f"http://{self.dump1090_host}:{self.dump1090_http_port}/skyaware/data/aircraft.json"
url = f"http://{self.dump1090_host}:{self.dump1090_http_port}{json_path}"
request_time = time() - request_start
response = json.loads(requests.get(url).text)

Expand Down Expand Up @@ -255,6 +259,7 @@ def make_dump1090() -> Dump1090PubSub:
mqtt_ip=os.environ.get("MQTT_IP", ""),
dump1090_host=os.environ.get("DUMP1090_HOST", ""),
dump1090_http_port=os.environ.get("DUMP1090_HTTP_PORT", ""),
json_path=os.environ.get("JSON_PATH", "/skyaware/data/aircraft.json"),
update_time=float(os.getenv("DUMP1090_UPDATE_TIME", 1)),
ads_b_json_topic=os.getenv("ADS_B_JSON_TOPIC", ""),
ground_level=float(os.getenv("GROUND_LEVEL", os.getenv("ALT", 0))),
Expand Down

0 comments on commit 49cd93b

Please sign in to comment.