Skip to content

Commit

Permalink
Update docker-compose.yml and send_data.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ersanyamarya committed Apr 8, 2024
1 parent 62a489d commit e810319
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ services:
context: ../
dockerfile: docker/Dockerfile
environment:
EGRESS_URLS: https://webhook.site/96500764-c8cb-4945-9caf-da2693fe28eb
MODULE_NAME: "http-client-requests"
MODULE_TYPE: "Input"
URLS: "https://catfact.ninja/fact"
URL: http://192.168.178.64/Gpio/v1/Sensor/bme280
METHOD: "GET"
AUTH_TOKEN: ""
POLL_INTERVAL: "5"
POLL_INTERVAL: "10"
PAYLOAD: ""
HEADER: ""
LOG_LEVEL: "DEBUG"
ports:
- 80:80
volumes:
- ../src:/app/src
11 changes: 10 additions & 1 deletion src/api/send_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from os import getenv
from requests import exceptions, post
from logging import getLogger
import json

log = getLogger("send_data")

Expand All @@ -32,7 +33,7 @@ def send_data(processed_data: any) -> str:
# fan-out
for url in urls:
# send data to the next module
response = post(url=url, json={"payload": processed_data})
response = post(url=url, json=convert_json_string_to_dict(processed_data))
log.debug(
f"Sent data to url {url} | Response: {response.status_code} {response.reason}"
)
Expand All @@ -59,3 +60,11 @@ def send_data(processed_data: any) -> str:
exceptions.ConnectTimeout,
) as e:
return f"Exception when sending data to the next module: {e}"
# function to convert json string to dictionary if possible otherwise return the string


def convert_json_string_to_dict(data: str) -> dict:
try:
return json.loads(data)
except json.JSONDecodeError:
return {"payload": data}

0 comments on commit e810319

Please sign in to comment.