mirror of
https://github.com/unixtensor/proxmox-ntfy.git
synced 2025-06-28 03:28:05 +00:00
Use requests
module instead of curl and use python3 main.py server.com
instead of --server=server.com
This commit is contained in:
@ -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")
|
||||
|
13
src/main.py
13
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"]):
|
||||
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,
|
||||
cli_args.server,
|
||||
sys.argv[1],
|
||||
cli_args.update_rate,
|
||||
)
|
||||
else:
|
||||
print(_ntfy_configure_prompt)
|
@ -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}")
|
||||
|
@ -11,9 +11,3 @@ def installed(package_name: str) -> Optional[bool]:
|
||||
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
|
Reference in New Issue
Block a user