file_import_upload_project

UPLOAD PROJECT
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()) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值