def setup(self): prefix = 'window/' width, height = CONF.get('main', prefix + 'size') self.resize(QSize(width, height)) posx, posy = CONF.get('main', prefix + 'position') self.move(QPoint(posx, posy)) # Is maximized? if CONF.get('main', prefix + 'is_maximized'): self.setWindowState(Qt.WindowMaximized) # Is fullscreen? if CONF.get('main', prefix + 'is_fullscreen'): self.setWindowState(Qt.WindowFullScreen)
def __init__(self, update_handler=_update_handler): host = CONF.get('DEFAULT', 'redis_host') port = CONF.getint('DEFAULT', 'redis_port') self.cli = redis.StrictRedis(host=host, port=port, db=0) self.pubsub = self.cli.pubsub() self.update_handler = update_handler
import time, random from kafka import KafkaProducer from config import CONF host = CONF.get('DEFAULT', 'kafka_host') port = CONF.get('DEFAULT', 'kafka_port') broker = host + ':' + port topic = CONF.get('DEFAULT', 'events_topic') producer = KafkaProducer(bootstrap_servers=broker) keys = ['foo', 'bar', 'buz'] i = 0 while True: msg = random.choice(keys) producer.send(topic, msg).get(timeout=60) i += 1 if i % 1000 == 0: print '>>>', i, 'messages sent'
import time from db import Updater from kafka import KafkaProducer from config import CONF host = CONF.get('DEFAULT', 'kafka_host') port = CONF.get('DEFAULT', 'kafka_port') broker = host + ':' + port topic = CONF.get('DEFAULT', 'updates_topic') partition = 0 producer = KafkaProducer(bootstrap_servers=broker) def forward_to_kafka(message): producer.send(topic, message['data'], partition=partition).get(timeout=60) u = Updater(update_handler=forward_to_kafka) u.run_updates_listener() try: while True: key = raw_input('KEY:\t') value = raw_input('VAL:\t') u.update(key, value) time.sleep(0.1) except KeyboardInterrupt: print 'Bye' finally: u.stop_listener()
import sys from config import CONF from kafka import KafkaConsumer, TopicPartition if len(sys.argv) == 1: print "Pass topic name in, please" sys.exit(1) host = CONF.get('DEFAULT', 'kafka_host') port = CONF.get('DEFAULT', 'kafka_port') broker = host + ':' + port topic = sys.argv[1] partition = 0 consumer = KafkaConsumer(bootstrap_servers=broker) tp = TopicPartition(topic, partition) consumer.assign([tp, ]) consumer.seek_to_beginning(tp) for msg in consumer: print '>>>', msg