diff --git a/notification_producer/producer_client.py b/notification_producer/producer_client.py index f0623c8..5da4cb1 100644 --- a/notification_producer/producer_client.py +++ b/notification_producer/producer_client.py @@ -23,6 +23,7 @@ import struct import sys from rich.console import Console from rich.prompt import Prompt +from notification_producer.timestamp import Timestamp class ProducerClient: @@ -38,9 +39,11 @@ class ProducerClient: async def connect(self): try: self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) - self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).') + now = Timestamp.now() + self.console.print(f'[yellow b][INFO][/][#8abeb7 b][{now}][/] Connected to the server ({self.__ip}:{self.__port}).') except ConnectionRefusedError: - sys.stderr.write("Could not connect to the server. Please, check the ip and the port.\n") + now = Timestamp.now() + sys.stderr.write(f"[ERROR][{now}] Could not connect to the server. Please, check the ip and the port.\n") sys.exit(1) async def send(self, message: str): @@ -63,7 +66,8 @@ class ProducerClient: await self.send_notification(title, message) if title == '' and message == '': - self.console.print(f"[yellow b][INFO][/] Finished.") + now = Timestamp.now() + self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] Finished.") self.console.print("[green]bye[/]") break @@ -71,6 +75,8 @@ class ProducerClient: pass except KeyboardInterrupt: await self.send_notification('', '') + now = Timestamp.now() + self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] Finished.") self.console.print("\n[green]bye[/]") sys.exit(0) finally: diff --git a/notification_producer/timestamp.py b/notification_producer/timestamp.py new file mode 100644 index 0000000..3571f02 --- /dev/null +++ b/notification_producer/timestamp.py @@ -0,0 +1,7 @@ +from datetime import datetime + +class Timestamp: + @staticmethod + def now() -> str: + return str(datetime.now()) +