server.py:
```python
import asyncio
import websockets
import subprocess
async def echo(websocket, path):
dch = await websocket.recv()
dch_folder = "restr" + dch
count = 1
while os.path.exists(os.path.join('D:\cj', dch_folder)):
dch_folder = "restr" + dch + "_" + str(count)
count += 1
os.makedirs(os.path.join('D:\cj', dch_folder, 'photos'))
os.makedirs(os.path.join('D:\cj', dch_folder, 'kmls'))
os.makedirs(os.path.join('D:\cj', dch_folder, 'project'))
photos_folder = os.path.join('D:\cj', dch_folder, 'photos')
kmls_folder = os.path.join('D:\cj', dch_folder, 'kmls')
project_folder = os.path.join('D:\cj', dch_folder, 'project')
async for file in websocket:
filename = file.filename
file.save(os.path.join(photos_folder, filename))
dh = await websocket.recv()
src_path = os.path.join(r'D:/911kml/', dh + '.xlsx.kml')
dst_path = os.path.join(r'D:/cj', dch_folder, 'kmls/', dh + '.xlsx.kml')
shutil.copy(src_path, dst_path)
process = await asyncio.create_subprocess_exec(
"python", "restruct.py", dch, photos_folder, project_folder, kmls_folder,
stdout=asyncio.subprocess.PIPE
)
while True:
output = await process.stdout.readline()
if output == b'':
break
await websocket.send(output.decode())
async def main():
async with websockets.serve(echo, "localhost", 8765):
await asyncio.Future() # run forever
if __name__ == "__main__":
asyncio.run(main())
```
client.py:
```python
import asyncio
import websockets
import aiohttp
async def upload_files(dch, files, dh):
async with aiohttp.ClientSession() as session:
async with session.ws_connect('ws://localhost:8765') as ws:
await ws.send(dch)
for file in files:
await ws.send(file)
await ws.send(dh)
async for message in ws:
print(message)
async def main():
dch = 'example'
files = ['example1.jpg', 'example2.jpg']
dh = 'example'
await upload_files(dch, files, dh)
if __name__ == "__main__":
asyncio.run(main())
```