mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 14:51:22 +00:00
22 lines
631 B
Python
22 lines
631 B
Python
from datetime import datetime
|
|
|
|
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
|
|
|
|
|
class MessageSender:
|
|
def __init__(self, custom_anchor: str = None):
|
|
self.server_connector = ServerUplinkConnector()
|
|
self.anchor = custom_anchor or 'message'
|
|
|
|
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)
|