import os import time from classes.CKafkaPC import KafkaPC print("start 1p_count_up") env_vars = { "config_path": os.getenv("config_path"), "config_section": os.getenv("config_section"), } new_p = KafkaPC(**env_vars) for i in range(10): message = {"count": i * 2} new_p.send_msg(message) print(f"Sent message {i} with count={i*2}") time.sleep(1)
), User( id_str="1236", user_name="user3", user_location="Bonn", account_created_at="2020-08-28 10:17", statuses_count=8, favorites_count=23, followers_count=9, friends_count=8, verified=True, ), ] for user in user_info: author = { "id_str": user.id_str, "user_name": user.user_name, "user_location": user.user_location, "account_created_at": user.account_created_at, "statuses_count": user.statuses_count, "favorites_count": user.favorites_count, "followers_count": user.followers_count, "friends_count": user.friends_count, "verified": user.verified, } new_pc.send_msg(author) print(f"Sent user:\n{author}") time.sleep(3)
import json import os from time import sleep from classes.CKafkaPC import KafkaPC def load_data(file): with open(file) as f: return json.load(f) data = load_data("./data/plot_topic_200k_unfunktionabel.json") env_vars = { 'config_path': os.getenv('config_path'), 'config_section': os.getenv('config_section') } new_pc = KafkaPC(**env_vars) max_iteration = 100 iteration = 0 message_count = 0 while iteration < max_iteration: iteration += 1 for row in data: message_count += 1 print(f"Iteration {iteration}, Message {message_count}") new_pc.send_msg(row) sleep(0.02)
import json import os from time import sleep from classes.CKafkaPC import KafkaPC def load_data(file): with open(file) as f: return json.load(f) data = load_data("./data/data.json") env_vars = { 'config_path': os.getenv('config_path'), 'config_section': os.getenv('config_section') } new_pc = KafkaPC(**env_vars) for topic, rows in data.items(): # checks if topic is a valid outgoing topic as specified in config.yml if topic not in new_pc.out_topic: continue else: print(f"Send data for topic: {topic}") for row in rows: print(row) new_pc.send_msg(row, topic=topic) sleep(1)