import argparse import subprocess import sys from pathlib import Path MSG_ROUTE = "/" def send_post_request(sock_path: Path, route: str, msg: str) -> int: command = ["/usr/bin/curl", "-X", "POST", "--unix-socket", str(sock_path), f"http://localhost{route}", "-d", msg] ret = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if ret.returncode != 0: print(f"Failed to send post request: {ret.stderr.decode()}") return ret.returncode print(ret.stdout.decode()) print("OK") return 0 if __name__ == "__main__": parser = argparse.ArgumentParser( prog="telegram_notifier_client", description="Interact with the listening sock for the Telegram notifier", ) parser.add_argument("-f", "--filename", type=str, help="Path for the listening sock", default="") parser.add_argument("-i", "--input", type=str, help="Message to send", default="hello world") args = parser.parse_args() sys.exit(send_post_request(args.filename, MSG_ROUTE, args.input))