baseimage-tutorial-framework/lib/tfw/message_sender.py

19 lines
562 B
Python

from datetime import datetime
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
class MessageSender:
def __init__(self, custom_key: str = None):
self.server_connector = ServerUplinkConnector()
self.key = custom_key or 'message'
def send(self, originator, message):
data = {
'originator': originator,
'timestamp': datetime.now().isoformat(),
'message': message
}
response = {'data': data}
self.server_connector.send(self.key, response)