YouTube_captions_search_engine/website/search.py
Benjamin Loison 126cc75dc6 Make WebSocket able to manage arbitrary feedback to end-user
While previous implementation was able to send two independent messages, now we can send an arbitrary amount of independent messages.
2023-02-07 17:25:17 +01:00

29 lines
519 B
Python
Executable File

#!/usr/bin/python3
import sys, time, fcntl, os
clientId = sys.argv[1]
message = sys.argv[2]
clientFilePath = f'users/{clientId}.txt'
def write(s):
f = open(clientFilePath, 'w+')
try:
fcntl.flock(f, fcntl.LOCK_EX)
if f.read() == '':
f.write(s)
else:
f.close()
time.sleep(1)
write(s)
except Exception as e:
print(e)
f.close()
for i in range(10):
write(f'{i}: {message}')
time.sleep(2)
os.remove(clientFilePath)