This repository has been archived on 2020-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
producer/messagesender.py

47 lines
1.1 KiB
Python
Raw Normal View History

2020-03-29 15:26:43 +02:00
#!/usr/bin/env python
import logging
2020-03-29 16:33:18 +02:00
import random
import string
from communicator import Communicator
2020-03-29 15:26:43 +02:00
"""
Message sender component
2020-03-29 15:26:43 +02:00
"""
__author__ = "@kovacsbence"
2020-03-29 15:26:43 +02:00
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
__module_name__ = "messagesender"
__version__text__ = "1"
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
def __init__(self, communicator: Communicator):
2020-03-29 15:26:43 +02:00
"""
Inicializálja az osztályt.
"""
self.communicator = communicator
2020-03-29 16:33:18 +02:00
def randomstring(self, stringLength) -> str:
2020-03-29 16:33:18 +02:00
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def sendmessage(self, message: str = "") -> None:
2020-03-29 15:26:43 +02:00
"""
Uzenet letrehozasa
:param message:
2020-03-29 15:26:43 +02:00
:return: str tipus
"""
if not message:
data = self.randomstring(32)
else:
data = message
self.communicator.sendmessage(data)