diff --git a/src/cli.py b/src/cli.py index 0216baa..f845e8a 100644 --- a/src/cli.py +++ b/src/cli.py @@ -2,7 +2,6 @@ import argparse def interface(): parser = argparse.ArgumentParser() - parser.add_argument("--server", required=True, help="") parser.add_argument("--cpu-temp-critical", type=int, default=80, help="cpu tempature crtitical. default = 80") parser.add_argument("--cpu-temp-warning", type=int, default=70, help="cpu tempature warning. default = 70") parser.add_argument("--update-rate", type=int, default=1, help="how often updates happen in seconds. default = 1") diff --git a/src/main.py b/src/main.py index 99feda5..d324ad9 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import time +import sys import package import cli @@ -6,6 +7,11 @@ import cpu from ntfy import Ntfy +_ntfy_configure_prompt = """\033[4mPlease configure an ntfy url before starting.\033[0m +Examples: +\033[32mpython3 main.py 10.0.13.37:42069 +python3 main.py ntfy.domain.com\033[0m""" + def start( cpu_critical_temp: int, cpu_warning_temp: int, @@ -23,11 +29,14 @@ def start( time.sleep(interval) if __name__ == "__main__": - if package.installed_list(["lm-sensors", "ntfy", "curl"]): - cli_args = cli.interface() - start( - cli_args.cpu_temp_critical, - cli_args.cpu_temp_warning, - cli_args.server, - cli_args.update_rate, - ) \ No newline at end of file + if package.installed("lm-sensors"): + if len(sys.argv) > 1: + cli_args = cli.interface() + start( + cli_args.cpu_temp_critical, + cli_args.cpu_temp_warning, + sys.argv[1], + cli_args.update_rate, + ) + else: + print(_ntfy_configure_prompt) \ No newline at end of file diff --git a/src/ntfy.py b/src/ntfy.py index c7cc9b1..2db09ac 100644 --- a/src/ntfy.py +++ b/src/ntfy.py @@ -1,4 +1,4 @@ -import subprocess +import requests class Ntfy: def __init__(self, server: str): @@ -6,6 +6,6 @@ class Ntfy: def send(self, message: str): try: - subprocess.run(["curl", "-d", f"\"{message}\"", self.server], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + requests.post(self.server, data=message) except Exception as err: print(f"Ntfy failed. {err}") diff --git a/src/package.py b/src/package.py index e7f760e..ec95cf5 100644 --- a/src/package.py +++ b/src/package.py @@ -10,10 +10,4 @@ def installed(package_name: str) -> Optional[bool]: return installed except Exception as err: print(err) - return None - -def installed_list(package_name_list: list[str]) -> bool: - for pkg_name in package_name_list: - if not installed(pkg_name): - return False - return True \ No newline at end of file + return None \ No newline at end of file