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

22 lines
631 B
Python
Raw Normal View History

from datetime import datetime
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
2018-01-29 15:48:32 +00:00
class MessageSender:
2018-02-02 16:30:26 +00:00
def __init__(self, custom_anchor: str = None):
2018-01-29 15:48:32 +00:00
self.server_connector = ServerUplinkConnector()
self.anchor = custom_anchor or 'message'
2018-01-29 15:48:32 +00:00
def send(self, originator, message):
data = {
'originator': originator,
'timestamp': datetime.now().isoformat(),
'message': message
}
response = {
'anchor': self.anchor,
'data': data
}
self.server_connector.send(self.anchor, response)