From 57c8b81c13e665ceaa6a63cc14698a8191c80c1f Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:56:00 +0300 Subject: [PATCH] Add format_number function to checker.py for improved subscription ID formatting This update introduces a new `format_number` function that formats subscription IDs into a more readable format (e.g., converting 1000 to '1k'). The `check_logs` function has been modified to utilize this new formatting for both head subscription ID and last subscription ID in the status messages, enhancing clarity in log analysis and improving the overall readability of subscription status reporting. --- checker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/checker.py b/checker.py index a89af00..26c564d 100644 --- a/checker.py +++ b/checker.py @@ -134,6 +134,12 @@ def clean_ansi(text): ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') return ansi_escape.sub('', text) +def format_number(number_str): + number = int(number_str) + if number >= 1000: + return f"{number//1000}k" + return str(number) + def check_logs(logger): try: logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True) @@ -155,11 +161,11 @@ def check_logs(logger): if head_sub_id: logger.info(f"Head sub id: {head_sub_id}") - return {"status": f"OK: {head_sub_id}"} + return {"status": f"OK: {format_number(head_sub_id)}"} if last_subscription_id: logger.info(f"Subscription: {last_subscription_id}") - return {"status": f"Sync: {last_subscription_id}"} + return {"status": f"Sync: {format_number(last_subscription_id)}"} logger.info("Not found subscription") return {"status": "Idle"}