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",
|
5554, "--producer-port", "-l",
|
||||||
help="The server's port to listen [b]producers[/].",
|
help="The server's port to listen [b]producers[/].",
|
||||||
rich_help_panel="Connection",
|
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:
|
try:
|
||||||
server = Server(ip, port, producer_port)
|
server = Server(ip, port, producer_port, notification_dir)
|
||||||
asyncio.run(server.up())
|
asyncio.run(server.up())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|||||||
@@ -18,18 +18,18 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
from rich.console import Console
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from rich.console import Console
|
||||||
from notification_server.notification_saver import NotificationSaver
|
from notification_server.notification_saver import NotificationSaver
|
||||||
from notification_server.timestamp import Timestamp
|
from notification_server.timestamp import Timestamp
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
BUFFER_SIZE = 1024
|
BUFFER_SIZE = 1024
|
||||||
NOTIFICATION_DIR = 'notifications'
|
NOTIFICATION_DIR = None
|
||||||
console = Console()
|
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.NOTIFICATION_DIR = notification_dir
|
||||||
self.__client_socket = None
|
self.__client_socket = None
|
||||||
self.__producer_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.")
|
self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] The producer ({addr[0]}:{addr[1]}) finished.")
|
||||||
break
|
break
|
||||||
|
|
||||||
now = Timestamp.now()
|
if not self.NOTIFICATION_DIR is None:
|
||||||
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
now = Timestamp.now()
|
||||||
|
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
||||||
|
|
||||||
await self.broadcast_message(title)
|
await self.broadcast_message(title)
|
||||||
await self.broadcast_message(message)
|
await self.broadcast_message(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user