From 1e95d9e72afbad93b0374d5391621e74eb0f59ce Mon Sep 17 00:00:00 2001 From: sHa Date: Mon, 8 Apr 2024 13:10:29 +0300 Subject: [PATCH] Refactor sleep logic in main.py and update status_send.py --- main.py | 5 ++++- processors/status_send.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b7bdc0d..3a954b6 100644 --- a/main.py +++ b/main.py @@ -38,7 +38,10 @@ def main(source: str = "autodetect", destination: str = "mattermost"): status_curr = status if not status_result: continue - time.sleep(status.get("duration") or SLEEP_TIME) + sleep = status.get("remaining_time") or status.get("duration") + if sleep is None or sleep <= 0: + sleep = SLEEP_TIME + time.sleep(sleep) if __name__ == "__main__": diff --git a/processors/status_send.py b/processors/status_send.py index d5de72b..fab3a37 100644 --- a/processors/status_send.py +++ b/processors/status_send.py @@ -44,7 +44,8 @@ class StatusSend: "expires_at": expires_at.isoformat() if expires_at else None, } now = time.strftime("%H:%M:%S", time.localtime()) - print(f"{now} Setting status to {self.destination.capitalize()} of {emoji.get("icon")} {text} ⏱️ for {duration} seconds") + remaining_time = round(kwargs.get("remaining_time", 0)) + print(f"{now} Setting status to {self.connector.NAME} of {emoji.get("icon")} {text} ⏱️ for {remaining_time} seconds") try: self.connector.send(data=data) except Exception as e: