diff --git a/server/scripts/ttn-webhook-dummy.py b/server/scripts/ttn-webhook-dummy.py index 77c02f2..ac1c4a2 100644 --- a/server/scripts/ttn-webhook-dummy.py +++ b/server/scripts/ttn-webhook-dummy.py @@ -15,7 +15,6 @@ def send_post_request(uri, data): except requests.exceptions.RequestException as e: pass - def main(): parser = argparse.ArgumentParser( description="Read JSON files and send them as POST requests to simulate a webhook request." @@ -41,6 +40,16 @@ def main(): ) args = parser.parse_args() + if args.mode == "send_one": + if os.path.isfile(args.directory) and args.directory.endswith(".json"): + with open(args.directory, "r", encoding="utf-8") as file: + try: + data = json.load(file) + print(f"Sending {args.directory} to {args.uri}") + send_post_request(args.uri, data) + except json.JSONDecodeError as e: + print(f"Error reading {args.directory}: {e}") + return if not os.path.exists(args.directory): print(f"Directory {args.directory} does not exist.")