mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 16:31:21 +00:00
22 lines
705 B
Python
22 lines
705 B
Python
import json
|
|
from datetime import datetime
|
|
|
|
from .networking.server_connector import ServerUplinkConnector
|
|
|
|
|
|
class MessageSender:
|
|
def __init__(self, custom_anchor=None):
|
|
self.server_connector = ServerUplinkConnector()
|
|
if isinstance(custom_anchor, str):
|
|
custom_anchor = custom_anchor.encode('utf-8')
|
|
self.anchor = custom_anchor or b'message'
|
|
|
|
def send(self, originator, message):
|
|
response = {
|
|
'originator': originator,
|
|
'timestamp': datetime.now().isoformat(),
|
|
'message': message
|
|
}
|
|
encoded_response = json.dumps(response).encode('utf-8')
|
|
self.server_connector.send(self.anchor, encoded_response)
|