/
ParaD
/
Server
Обзор
Документация
Войти
/
ParaD
/
Server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
updating_data.py
118 строк
4 KB
Rayfaga
first_commit
01 мар 2025, 20:02
01 мар 2025, 20:02
c75de2b
Код
Авторство
О чём код?
import socket import time import threading from talk.send_csv import start_file_send from talk.receive_csv import start_server_csv from talk.send_txt import start_file_send from talk.receive_txt import start_server_received HOST = '' # Введите IP-адрес принимающего ноутбука (или оставьте пустым для привязки ко всем интерфейсам) PORT = 1025 # Любой свободный порт (например, 12345) def timer(): global timer_done time.sleep(24) timer_done = 2 updates = [['', '', ''], #1 ['', '', ''], #2 ['', '', ''], #3 ['', '', ''], #4 ['', '', ''], #5 ['', '', ''], #6 ['', '', ''], #7 ['', '', '']] #8 for i in range(1, 9): with open(f'./variable_txt/robot{i}/URL_robot{i}.txt', 'r') as f: updates[i-1][0]=f.readlines()[0] start_server_received() data1='' data2='' timer_done = 0 while 1: if timer_done == 0: timer_done = 1 threading.Thread(target=timer, daemon=True).start() if timer_done == 2: timer_done = 0 for i in range(0, 8): for j in range(len(updates[i])): if j==1: if updates[i][j]=='': with open(f'./variable_txt/robot{i+1}/charge.txt', 'w') as f: f.write("4") if j==2: if updates[i][j]=='': with open(f'./variable_txt/robot{i+1}/errors.txt', 'w', encoding='utf-8') as f: f.write("отсутствия подключения!") updates[i][1] = '' updates[i][2] = '' with open("./variable_txt/from_comp.txt", "r") as f: data1 = f.readline() if data1!='': data1 = data1.split("_") #[1]_COMP_123 A=[] if data1[1] == "COMP": A=data1[0][1:-1] A=A.split(', ') for i in range(len(A)): with open(f"./variable_txt/robot{i+1}/URL_robot{i+1}.txt", 'r') as f: ip = f.readline() start_file_send(f"./cart/carts/{data1[-1]}.txt", ip) time.sleep(2) start_file_send(f"./cart/carts/{data1[-1]}.png", ip) #[1]_FUNCTION_1 A=[] if data1[1] == "FUNCTION": A=data1[0][1:-1] A=A.split(', ') for i in range(len(A)): with open(f"./variable_txt/robot{i+1}/URL_robot{i+1}.txt", 'r') as f: ip = f.readline() with open("./talk/send.txt", "w") as f: f.write(f"{data1[2]}_FUNCTION") start_file_send(f"./talk/send.txt", ip) #1_VAGON_[1, 3, 4, 6, 7] if data1[1] == "VAGON": with open(f"./variable_txt/robot{data1[0]}/URL_robot{data1[0]}.txt", 'r') as f: ip = f.readline() with open("./talk/send.txt", "w") as f: f.write(f"{"-".join(data1[2][1:-1].split(', '))}_VAGON") start_file_send(f"./talk/send.txt", ip) open("./variable_txt/from_comp.txt", "w").close() ''' 192.168.150.230 charge/-/1 errors/-/нет logs/-/1223 3221 ''' with open('./talk/received.txt', 'r', encoding='utf-8') as f: data2=f.readlines() open('./talk/received.txt', 'w').close() if data2!=[]: if len(data2)==1: with open('./talk/for_server.txt', 'w', encoding='utf-8') as f: print(data2) f.write(str(data2[0])) else: for i in range(len(data2)): data2[i]=data2[i].replace('\n', '') for i in range(1, 9): if updates[i-1][0]==data2[0]: updates[i-1][1]=data2[1].split('/-/')[1] with open(f'./variable_txt/robot{i}/charge.txt', 'w') as f: f.write(str(updates[i-1][1])) updates[i-1][2]=data2[2].split('/-/')[1] with open(f'./variable_txt/robot{i}/errors.txt', 'w', encoding='utf-8') as f: f.write(str(updates[i-1][2])) with open(f'./variable_txt/robot{i}/logs.txt', 'w') as f: for j in range(3, len(data2)): if j==3: f.write(str(data2[j].split('/-/')[1])+'\n') else: f.write(str(data2[j])+'\n') break