Add a option to turn on saving and choose a folder of notifications.
This commit is contained in:
@@ -44,6 +44,12 @@ def up(
|
||||
5554, "--producer-port", "-l",
|
||||
help="The server's port to listen [b]producers[/].",
|
||||
rich_help_panel="Connection",
|
||||
),
|
||||
notification_dir: str = typer.Option(
|
||||
None, "--notification-dir", "-d",
|
||||
help="The server will save notifications to the directory by the path. Does not save if this option is not provided.",
|
||||
rich_help_panel="Persistence",
|
||||
show_default=False,
|
||||
)
|
||||
):
|
||||
"""
|
||||
@@ -51,7 +57,7 @@ def up(
|
||||
"""
|
||||
|
||||
try:
|
||||
server = Server(ip, port, producer_port)
|
||||
server = Server(ip, port, producer_port, notification_dir)
|
||||
asyncio.run(server.up())
|
||||
except KeyboardInterrupt:
|
||||
console = Console()
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
###############################################################################
|
||||
|
||||
import struct
|
||||
from rich.console import Console
|
||||
import asyncio
|
||||
from rich.console import Console
|
||||
from notification_server.notification_saver import NotificationSaver
|
||||
from notification_server.timestamp import Timestamp
|
||||
|
||||
|
||||
class Server:
|
||||
BUFFER_SIZE = 1024
|
||||
NOTIFICATION_DIR = 'notifications'
|
||||
NOTIFICATION_DIR = None
|
||||
console = Console()
|
||||
|
||||
def __init__(self, ip: str, port: int, producer_port: int, notification_dir: str = 'notifications'):
|
||||
def __init__(self, ip: str, port: int, producer_port: int, notification_dir: str | None = None):
|
||||
self.NOTIFICATION_DIR = notification_dir
|
||||
self.__client_socket = None
|
||||
self.__producer_socket = None
|
||||
@@ -88,8 +88,9 @@ class Server:
|
||||
self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] The producer ({addr[0]}:{addr[1]}) finished.")
|
||||
break
|
||||
|
||||
now = Timestamp.now()
|
||||
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
||||
if not self.NOTIFICATION_DIR is None:
|
||||
now = Timestamp.now()
|
||||
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
||||
|
||||
await self.broadcast_message(title)
|
||||
await self.broadcast_message(message)
|
||||
|
||||
Reference in New Issue
Block a user