Exemple #1
0
class FlaskRelayer(object):

    def __init__(self, app: Flask = None, logging_topic: str = None, kafka_hosts: str = None, **kwargs: str) -> None:
        if app:
            self.init_app(
                app,
                logging_topic,
                kafka_hosts=kafka_hosts,
                **kwargs,
            )

    def init_app(self, app: Flask, logging_topic: Any, kafka_hosts: str = None, **kwargs: str) -> None:
        kafka_hosts = kafka_hosts or app.config.get('KAFKA_HOSTS')
        self.event_relayer = Relayer(
            logging_topic,
            kafka_hosts=kafka_hosts,
            **kwargs,
        )

    def emit(self, *args: str, **kwargs: str) -> None:
        self.event_relayer.emit(*args, **kwargs)

    def emit_raw(self, *args: Any, **kwargs: Any) -> None:
        self.event_relayer.emit_raw(*args, **kwargs)

    def log(self, *args: str, **kwargs: str) -> None:
        self.event_relayer.log(*args, **kwargs)

    def flush(self, *args: str, **kwargs: str) -> None:
        self.event_relayer.flush()
Exemple #2
0
class TestRelayer(BaseTestCase):
    def setUp(self) -> None:
        super().setUp()
        self.relayer = Relayer('log', kafka_hosts='foo')

    def test_requires_kafka_hosts(self) -> None:
        self.assertRaises(ConfigurationError, Relayer, 'foo')

    def test_emit(self) -> None:
        self.relayer.emit('type', 'subtype', 'payload')

    def test_emit_with_partition_key(self) -> None:
        self.relayer.emit('type', 'subtype', 'payload', 'key')

    def test_source_not_present(self) -> None:
        relayer = Relayer('log', kafka_hosts='foo', topic_prefix='pre', topic_suffix='su')
        assert relayer.source == 'prelogsu'

    def test_source(self) -> None:
        relayer = Relayer('log', kafka_hosts='foo', source='container_1')
        assert relayer.source == 'container_1'

    def test_emit_raw(self) -> None:
        self.relayer.emit_raw('topic', {'message': 'content'}, 'key')

    def test_flush(self) -> None:
        self.relayer.flush()
        assert self.relayer._producer.flushed
Exemple #3
0
 def init_app(self, app: Flask, logging_topic: Any, kafka_hosts: str = None, **kwargs: str) -> None:
     kafka_hosts = kafka_hosts or app.config.get('KAFKA_HOSTS')
     self.event_relayer = Relayer(
         logging_topic,
         kafka_hosts=kafka_hosts,
         **kwargs,
     )
from relayer import Relayer

relayer = Relayer()

relayer.print_keys()

print "connected?", relayer.check_connection()

print("connecting...")
relayer.connect()

print "connected?", relayer.check_connection()

while True:

    x = raw_input("F B L R A H D S X:")

    if x == 'F':
        relayer.command("forward")

    if x == 'B':
        relayer.command("back")

    if x == 'L':
        relayer.command("left")

    if x == 'R':
        relayer.command("right")

    if x == 'A':
        relayer.command("move arms")
import sys

############################################################

TRIGGER_WORD = "robot"
directive = Directive(TRIGGER_WORD)

NESTLE_VIDEOS = "/home/pi/hellobot/mped_videos/"         
responder = Responder(path = NESTLE_VIDEOS)         # plays video on screen 

PIR_PIN = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN)

listener = Listener()                               # listens to microphone and outputs text
relayer = Relayer()                                 # communicates to arduino

############################################################

def get_nestle_response(phrase):  
  
  if "hello" in phrase or "hey" in phrase or "hi" in phrase: #greet
    key = "hello" + str(randint(1, 3))
  elif "how" in phrase: #how are you?
    key = "how" + str(randint(1, 3))
  elif "up" in phrase or "whatsApp" in phrase: #what's up?
    key = "up" + str(randint(1, 3))
  elif "name" in phrase: #what's your name?
    key = "name" + str(randint(1, 2))
  elif "do" in phrase: #what do you do?
    key = "do" + str(randint(1, 3))
Exemple #6
0
 def setUp(self) -> None:
     super().setUp()
     self.relayer = Relayer('log', kafka_hosts='foo')