2020-03-29 15:26:43 +02:00
|
|
|
#!/usr/bin/env python
|
2020-03-29 20:00:27 +02:00
|
|
|
import logging
|
2020-03-29 16:33:18 +02:00
|
|
|
import random
|
|
|
|
import string
|
2020-03-29 20:00:27 +02:00
|
|
|
from communicator import Communicator
|
2020-03-29 15:26:43 +02:00
|
|
|
|
|
|
|
"""
|
2020-03-29 20:00:27 +02:00
|
|
|
Message sender component
|
2020-03-29 15:26:43 +02:00
|
|
|
"""
|
|
|
|
|
2020-03-29 20:00:27 +02:00
|
|
|
__author__ = "@kovacsbence"
|
2020-03-29 15:26:43 +02:00
|
|
|
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
|
|
|
__module_name__ = "messagesender"
|
|
|
|
__version__text__ = "1"
|
|
|
|
|
2020-03-29 20:00:27 +02:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-03-29 15:26:43 +02:00
|
|
|
class MessageSender:
|
|
|
|
"""
|
|
|
|
Üzenetek küldéséért felelős komponens.
|
|
|
|
"""
|
2020-03-29 16:33:18 +02:00
|
|
|
|
2020-03-29 20:00:27 +02:00
|
|
|
def __init__(self, communicator: Communicator):
|
2020-03-29 15:26:43 +02:00
|
|
|
"""
|
|
|
|
Inicializálja az osztályt.
|
|
|
|
"""
|
2020-03-29 20:00:27 +02:00
|
|
|
self.communicator = communicator
|
2020-03-29 16:33:18 +02:00
|
|
|
|
2020-03-30 19:33:09 +02:00
|
|
|
def randomstring(self, stringlength: int) -> str:
|
2020-03-29 16:33:18 +02:00
|
|
|
"""Generate a random string of fixed length """
|
|
|
|
letters = string.ascii_lowercase
|
2020-03-30 19:33:09 +02:00
|
|
|
return ''.join(random.choice(letters) for i in range(stringlength))
|
2020-03-29 16:33:18 +02:00
|
|
|
|
2020-03-29 20:00:27 +02:00
|
|
|
def sendmessage(self, message: str = "") -> None:
|
2020-03-29 15:26:43 +02:00
|
|
|
"""
|
2020-03-29 20:00:27 +02:00
|
|
|
Uzenet letrehozasa
|
|
|
|
:param message:
|
2020-03-29 15:26:43 +02:00
|
|
|
:return: str tipus
|
|
|
|
"""
|
2020-03-29 20:00:27 +02:00
|
|
|
if not message:
|
|
|
|
data = self.randomstring(32)
|
|
|
|
else:
|
|
|
|
data = message
|
|
|
|
self.communicator.sendmessage(data)
|