2018-04-03 12:49:14 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-01-30 16:24:17 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2018-04-06 13:21:45 +00:00
|
|
|
from tfw.networking.event_handlers import ServerUplinkConnector
|
2018-01-29 15:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MessageSender:
|
2018-02-21 14:28:16 +00:00
|
|
|
def __init__(self, custom_key: str = None):
|
2018-01-29 15:48:32 +00:00
|
|
|
self.server_connector = ServerUplinkConnector()
|
2018-02-21 14:28:16 +00:00
|
|
|
self.key = custom_key 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-28 14:57:44 +00:00
|
|
|
response = {'data': data}
|
2018-02-21 14:28:16 +00:00
|
|
|
self.server_connector.send(self.key, response)
|