From 928f1a56d4d27517f3eb5f05c0a9c48fc0192027 Mon Sep 17 00:00:00 2001 From: Awin Huang Date: Sat, 1 Feb 2025 23:36:36 +0800 Subject: [PATCH] Add time in message --- tapo_exporter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tapo_exporter.py b/tapo_exporter.py index e8f4e7c..6b44d74 100755 --- a/tapo_exporter.py +++ b/tapo_exporter.py @@ -4,6 +4,7 @@ import argparse import asyncio import json import time +import datetime from kasa import Discover from kasa.exceptions import KasaException @@ -95,7 +96,11 @@ def getSecrets(fileanme): return None +def getDatetime(): + return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + async def main(configs): + print(f"Start: {getDatetime()}") secrect = getSecrets(configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL)) if secrect is None: print(f'Cannot read secret file({configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL)})') @@ -141,7 +146,7 @@ async def main(configs): if ENABLE_EXPORTER: gaugeDict[gaugeName].set(value) - pp(f"Set {gaugeName}: {value}") + pp(f"[{getDatetime()}] Set {gaugeName}: {value}") time.sleep(pollingInterval) except KeyboardInterrupt: @@ -149,6 +154,7 @@ async def main(configs): break await t315.disconnect() + print(f"End: {getDatetime()}") if __name__ == "__main__":