mirror of
https://github.com/unixtensor/proxmox-ntfy.git
synced 2025-06-28 14:18:05 +00:00
Utilize cli.py
module for handling both arguments and argv
This commit is contained in:
29
src/cli.py
29
src/cli.py
@ -1,9 +1,26 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
def interface():
|
||||
parser = argparse.ArgumentParser()
|
||||
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")
|
||||
from typing import Optional
|
||||
|
||||
return parser.parse_args()
|
||||
_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"""
|
||||
|
||||
class Interface:
|
||||
def __init__(self):
|
||||
self.parser = argparse.ArgumentParser()
|
||||
self.parser.add_argument("--cpu-temp-critical", type=int, default=80, help="cpu tempature crtitical. default = 80")
|
||||
self.parser.add_argument("--cpu-temp-warning", type=int, default=70, help="cpu tempature warning. default = 70")
|
||||
self.parser.add_argument("--update-rate", type=int, default=1, help="how often updates happen in seconds. default = 1")
|
||||
|
||||
def parsed_args(self):
|
||||
return self.parser.parse_args()
|
||||
|
||||
def argv_1(self) -> Optional[str]:
|
||||
if len(sys.argv) > 1:
|
||||
return sys.argv[1]
|
||||
else:
|
||||
print(_ntfy_configure_prompt)
|
||||
return None
|
22
src/main.py
22
src/main.py
@ -1,5 +1,4 @@
|
||||
import time
|
||||
import sys
|
||||
|
||||
import package
|
||||
import cli
|
||||
@ -7,11 +6,6 @@ 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,
|
||||
@ -30,13 +24,13 @@ def start(
|
||||
|
||||
if __name__ == "__main__":
|
||||
if package.installed("lm-sensors"):
|
||||
if len(sys.argv) > 1:
|
||||
cli_args = cli.interface()
|
||||
cli_args = cli.Interface()
|
||||
parsed = cli_args.parsed_args()
|
||||
ntfy_server = cli_args.argv_1()
|
||||
if ntfy_server:
|
||||
start(
|
||||
cli_args.cpu_temp_critical,
|
||||
cli_args.cpu_temp_warning,
|
||||
sys.argv[1],
|
||||
cli_args.update_rate,
|
||||
parsed.cpu_temp_critical,
|
||||
parsed.cpu_temp_warning,
|
||||
ntfy_server,
|
||||
parsed.update_rate,
|
||||
)
|
||||
else:
|
||||
print(_ntfy_configure_prompt)
|
Reference in New Issue
Block a user