Last active
January 23, 2022 15:39
-
-
Save ashish-mj/58b082445b89019537b2796f9cb4d853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kafka import KafkaProducer | |
import os | |
from datetime import datetime | |
import time | |
now = datetime.now() | |
bootstrap_servers = ['localhost:9092'] | |
topicName = 'Media' | |
producer = KafkaProducer(bootstrap_servers = bootstrap_servers) | |
producer = KafkaProducer() | |
base_path = os.getcwd() | |
source = base_path+'/server/' | |
destination = base_path+'/local_dir/' | |
files = os.listdir(source) | |
time.sleep(15) | |
for file in files: | |
os.rename(source + file, destination + file) | |
current_time = now.strftime("%H:%M:%S") | |
data = {"time":current_time,"file_path":destination + file} | |
ack = producer.send(topicName, bytes(str(data), 'utf-8')) | |
print(ack.get()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment