2018-01-30 16:24:17 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2018-02-06 13:19:41 +00:00
|
|
|
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()
|
2018-02-02 15:49:15 +00:00
|
|
|
self.anchor = custom_anchor or 'message'
|
2018-01-29 15:48:32 +00:00
|
|
|
|
2018-01-30 16:24:17 +00:00
|
|
|
def send(self, originator, message):
|
2018-02-02 15:49:15 +00:00
|
|
|
data = {
|
2018-01-30 16:24:17 +00:00
|
|
|
'originator': originator,
|
|
|
|
'timestamp': datetime.now().isoformat(),
|
|
|
|
'message': message
|
|
|
|
}
|
2018-02-02 15:49:15 +00:00
|
|
|
response = {
|
|
|
|
'anchor': self.anchor,
|
|
|
|
'data': data
|
|
|
|
}
|
2018-02-02 17:39:06 +00:00
|
|
|
self.server_connector.send(self.anchor, response)
|