Implement websocket client & task execution

This commit is contained in:
2023-03-10 23:32:01 -06:00
parent e6d9683b63
commit b849702fb5

41
main.py
View File

@@ -1,21 +1,20 @@
from dotenv import load_dotenv
load_dotenv()
import asyncio import asyncio
import io import io
import os import os
from PIL import Image from PIL import Image
from websockets import connect
from dotenv import load_dotenv
from differencing import get_pixel_differences from client import PlaceClient
from network import upload from constants import Environment
# Start a websocket # Start a websocket
# In the initial image load, detect all changes between the target and # In the initial image load, detect all changes between the target and
load_dotenv()
width, height = int(os.getenv("CANVAS_WIDTH")), int(os.getenv("CANVAS_HEIGHT"))
async def get_image(websocket): async def get_image(websocket):
while True: while True:
@@ -25,26 +24,22 @@ async def get_image(websocket):
async def main(): async def main():
source_path = os.getenv("SOUCE_FILE") # Grab the image we want to setup
width, height = int(os.getenv(Environment.CANVAS_HEIGHT)), int(os.getenv(Environment.CANVAS_HEIGHT))
async with connect(os.getenv("WEBSOCKET_ADDRESS")) as websocket: original_image = Image.open(os.getenv(Environment.SOURCE_FILE))
while True:
print(websocket.messages)
original_image = Image.open(source_path)
original_image = original_image.resize((width, height), Image.LANCZOS) original_image = original_image.resize((width, height), Image.LANCZOS)
source = await get_image(websocket) # Start connection and get client connection protocol
ips = get_pixel_differences(source, original_image) client = await PlaceClient.connect(os.getenv(Environment.WEBSOCKET_ADDRESS))
client.current_target = original_image
asyncio.create_task(client.receive())
upload(ips) # await asyncio.sleep(2)
await client.complete(5)
if len(ips) < 5: print('Complete.')
break
original_image.close() return
break
if __name__ == "__main__": if __name__ == "__main__":