Working fifo input now.

This commit is contained in:
kalzu rekku 2024-02-11 12:33:13 +02:00
parent 8f80c98c77
commit b4068ff0de

View File

@ -1,6 +1,8 @@
import queue
import os
import time
import threading
import re
def main():
print("Hello There")
@ -19,28 +21,49 @@ def main():
output_thread.daemon = True
output_thread.start()
for num in range(21):
print(f"wait till full: {num}/20", end='\r')
countdown(config, event)
def countdown(config, event):
print(f"Speak to: {config['input']}")
print(f"Output is going to be: {config['output']}")
num = 0
while not event.is_set():
print(f"wait till full: {num}/~", end='\r')
time.sleep(0.5)
num = num + 1
print("\nDone!")
event.set()
def handle_input(que, event, config):
loop = 0
file = config['input']
try:
os.mkfifo(file)
except FileExistsError:
pass
with open(file, 'r') as in_fifo:
while not event.is_set():
message = f"{time.time()} | Hi! | {file} | {loop}"
fifo_read = in_fifo.readline().rsplit('\n')
if not fifo_read:
continue
message = fifo_read
que.put(message)
loop = loop + 1
time.sleep(1)
def handle_output(que, event, config):
file = '/tmp/test_out'
future_file = config['output']
file = config['output']
with open(file, 'a') as out_file:
while not event.is_set():
try:
message = que.get()
out_file.write(f"{future_file} | {message}\r\n")
except queue.Empty:
continue
if message == "":
continue
elif 'EXIT' in message:
event.set()
out_file.write(f"{time.time()} | Bye!\r\n")
out_file.flush()
else:
out_file.write(f"{time.time()} | {message[0]}\r\n")
out_file.flush()
time.sleep(1)