Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kafka.client import KafkaClient
- from kafka.consumer import SimpleConsumer
- from kafka.producer import SimpleProducer
- import time
- import random
- import logging
- logging.basicConfig(level=logging.INFO)
- s_nouns = ["A dude", "My mom", "The king", "Some guy", "A cat with rabies", "A sloth", "Your homie", "This cool guy my gardener met yesterday", "Superman"]
- p_nouns = ["These dudes", "Both of my moms", "All the kings of the world", "Some guys", "All of a cattery's cats", "The multitude of sloths living under your bed", "Your homies", "Like, these, like, all these people", "Supermen"]
- s_verbs = ["eats", "kicks", "gives", "treats", "meets with", "creates", "hacks", "configures", "spies on", "retards", "meows on", "flees from", "tries to automate", "explodes"]
- p_verbs = ["eat", "kick", "give", "treat", "meet with", "create", "hack", "configure", "spy on", "retard", "meow on", "flee from", "try to automate", "explode"]
- infinitives = ["to make a pie.", "for no apparent reason.", "because the sky is green.", "for a disease.", "to be able to make toast explode.", "to know more about archeology."]
- broker = 'localhost:9092'
- logging.info("Connecting to Kafka - {0}".format(broker))
- client = KafkaClient(broker)
- producer = SimpleProducer(client)
- # write out 1000 random sentences
- index = 0
- logging.info("sending strings")
- while index < 10000:
- index += 1
- sentence = random.choice(s_nouns) + " " + \
- random.choice(s_verbs) + " " + \
- random.choice(s_nouns).lower() or random.choice(p_nouns).lower() + " " + \
- random.choice(infinitives)
- producer.send_messages('myTopic', sentence)
- logging.info("sent {0} of 10000".format(index))
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement