diff --git a/notification_client/MessagePrinter.py b/notification_client/MessagePrinter.py index c149ece..7e863e5 100644 --- a/notification_client/MessagePrinter.py +++ b/notification_client/MessagePrinter.py @@ -3,10 +3,10 @@ from rich.markdown import Markdown class MessagePrinter: @staticmethod - def connected(ip, port): + def connected(ip, port, timestamp): console = Console() - console.print(f'[yellow b][INFO][/] Connected to the server ({ip}:{port}).') + console.print(f'[yellow b][INFO][/][#8abeb7 b][{timestamp}][/] Connected to the server ({ip}:{port}).') @staticmethod def print(title: str, message: str): @@ -16,6 +16,11 @@ class MessagePrinter: console.print(Markdown(full_message)) + @staticmethod + def printInfo(message: str, timestamp: str): + console = Console() + + console.print(f'[yellow b][INFO][/][#8abeb7 b][{timestamp}][/] {message}') @staticmethod def bye(): diff --git a/notification_client/client.py b/notification_client/client.py index c548dfd..a0f1e7e 100644 --- a/notification_client/client.py +++ b/notification_client/client.py @@ -23,6 +23,7 @@ import sys from notification_client.MessagePrinter import MessagePrinter from notification_client.notitication import Notification +from notification_client.timestamp import Timestamp class Client: @@ -35,9 +36,10 @@ class Client: async def connect(self): try: reader, writer = await asyncio.open_connection(self.__ip, self.__port) - MessagePrinter.connected(self.__ip, self.__port) + MessagePrinter.connected(self.__ip, self.__port, Timestamp.now()) 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) await self.handle(reader, writer) @@ -54,6 +56,8 @@ class Client: title = await self.receive_message(reader) message = await self.receive_message(reader) + now = Timestamp.now() + MessagePrinter.printInfo('A notification received from the server.', now) MessagePrinter.print(title, message) Notification.notify(title, message) diff --git a/notification_client/timestamp.py b/notification_client/timestamp.py new file mode 100644 index 0000000..3571f02 --- /dev/null +++ b/notification_client/timestamp.py @@ -0,0 +1,7 @@ +from datetime import datetime + +class Timestamp: + @staticmethod + def now() -> str: + return str(datetime.now()) +