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
Torma Kristóf 50dec05e6b
Some checks reported errors
continuous-integration/drone/pr Build was killed
continuous-integration/drone/push Build was killed
tests done
2020-03-30 19:33:09 +02:00

47 lines
1.1 KiB
Python

#!/usr/bin/env python
import logging
import random
import string
from communicator import Communicator
"""
Message sender component
"""
__author__ = "@kovacsbence"
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
__module_name__ = "messagesender"
__version__text__ = "1"
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)
class MessageSender:
"""
Üzenetek küldéséért felelős komponens.
"""
def __init__(self, communicator: Communicator):
"""
Inicializálja az osztályt.
"""
self.communicator = communicator
def randomstring(self, stringlength: int) -> str:
"""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:
"""
Uzenet letrehozasa
:param message:
:return: str tipus
"""
if not message:
data = self.randomstring(32)
else:
data = message
self.communicator.sendmessage(data)