[+] update status

1. add repeat_interval;
This commit is contained in:
Siarhei Siniak 2025-12-04 11:58:41 +03:00
parent 904c77fc29
commit 6410df3326
2 changed files with 82 additions and 30 deletions

@ -1,5 +1,8 @@
import sys
import datetime
import time
import os
import signal
import io
import json
import subprocess
@ -17,7 +20,48 @@ from typing import (
logger = logging.getLogger(__name__)
def get_info(
sh: list[str],
timeout: int | float,
):
t1: list[str] = []
for sh_index, o in enumerate(
[
*sh,
*[
r"""
A=$(free -h | grep -P Mem: | grep -Po '[\w\.\d]+');
echo -n $A | awk '{print $2, $7}';
""",
r"""
date +'%Y-%m-%d %l:%M:%S %p';
""",
],
]
):
try:
t1.append(
subprocess.check_output(
o,
shell=True,
timeout=timeout,
)
.decode('utf-8')
.strip()
)
except Exception:
t1.append('fail %d' % sh_index)
t3 = ' | '.join(t1).replace('\n\r', '')
sys.stdout.write(t3)
sys.stdout.flush()
def run(argv: list[str]):
logging.basicConfig(level=logging.INFO)
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
class c1(optparse.IndentedHelpFormatter):
@ -81,6 +125,13 @@ def run(argv: list[str]):
default=None,
type=float,
)
add_option(
parser,
'--repeat_interval',
dest='repeat_interval',
default=None,
type=float,
)
add_option(
parser,
'--config',
@ -122,40 +173,38 @@ printf '% 3.0f%%' $(upower -d | grep -Po 'percentage:\\s+\\d+(\\.\\d+)?%' | grep
options.sh.extend(config.get('sh', []))
t1: list[str] = []
last_ts = datetime.datetime.now()
for sh_index, o in enumerate(
[
*options.sh,
*[
r"""
A=$(free -h | grep -P Mem: | grep -Po '[\w\.\d]+');
echo -n $A | awk '{print $2, $7}';
""",
r"""
date +'%Y-%m-%d %l:%M:%S %p';
""",
],
]
):
try:
t1.append(
subprocess.check_output(
o,
shell=True,
shutdown: bool = False
def on_signal(*args: Any, **kwargs: Any):
nonlocal shutdown
shutdown = True
signal.signal(signal.SIGINT, on_signal)
signal.signal(signal.SIGTERM, on_signal)
while not shutdown:
get_info(
timeout=timeout2,
sh=options.sh,
)
.decode('utf-8')
.strip()
)
except Exception:
t1.append('fail %d' % sh_index)
t3 = ' | '.join(t1).replace('\n\r', '')
sys.stdout.write(t3)
if not options.repeat_interval:
break
else:
sys.stdout.write('\n')
sys.stdout.flush()
now_ts = datetime.datetime.now()
spent = (now_ts - last_ts).total_seconds()
last_ts = last_ts + datetime.timedelta(seconds=options.repeat_interval)
if spent < options.repeat_interval:
time.sleep(options.repeat_interval - spent)
if __name__ == '__main__':
run(sys.argv[1:])

BIN
releases/whl/online_fxreader_pr34-0.1.5.43-py3-none-any.whl (Stored with Git LFS) Normal file

Binary file not shown.