mirror of
https://github.com/unixtensor/proxmox-ntfy.git
synced 2025-06-28 08:48:04 +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 argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
def interface():
|
from typing import Optional
|
||||||
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")
|
|
||||||
|
|
||||||
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 time
|
||||||
import sys
|
|
||||||
|
|
||||||
import package
|
import package
|
||||||
import cli
|
import cli
|
||||||
@ -7,11 +6,6 @@ import cpu
|
|||||||
|
|
||||||
from ntfy import Ntfy
|
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(
|
def start(
|
||||||
cpu_critical_temp: int,
|
cpu_critical_temp: int,
|
||||||
cpu_warning_temp: int,
|
cpu_warning_temp: int,
|
||||||
@ -30,13 +24,13 @@ def start(
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if package.installed("lm-sensors"):
|
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(
|
start(
|
||||||
cli_args.cpu_temp_critical,
|
parsed.cpu_temp_critical,
|
||||||
cli_args.cpu_temp_warning,
|
parsed.cpu_temp_warning,
|
||||||
sys.argv[1],
|
ntfy_server,
|
||||||
cli_args.update_rate,
|
parsed.update_rate,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
print(_ntfy_configure_prompt)
|
|
Reference in New Issue
Block a user