forked from skp1919/HousePricePredictorHackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhousePricePredictorRequestStream.py
More file actions
32 lines (26 loc) · 2.78 KB
/
housePricePredictorRequestStream.py
File metadata and controls
32 lines (26 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python3
from kafka import KafkaProducer
from random import randint
from time import sleep
from csv import reader
import sys
BROKER = 'localhost:9092'
TOPIC = 'HousePricePredictorRequests'
try:
p = KafkaProducer(bootstrap_servers=BROKER)
except Exception as e:
print(f"ERROR --> {e}")
sys.exit(1)
while True:
message = []
with open('test.csv', 'r') as read_obj:
csv_reader = reader(read_obj)
header = next(csv_reader)
# Check file as empty
if header != None:
# Iterate over each row after the header in the csv
for row in csv_reader:
message = ', '.join(row)
print(f">>> '{message}'")
p.send(TOPIC, bytes(message,encoding="utf8"))
sleep(randint(1,4))