mirror of
https://github.com/Xevion/v6-place.git
synced 2025-12-10 00:09:01 -06:00
Implement websocket client & task execution
This commit is contained in:
43
main.py
43
main.py
@@ -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))
|
||||||
|
original_image = Image.open(os.getenv(Environment.SOURCE_FILE))
|
||||||
|
original_image = original_image.resize((width, height), Image.LANCZOS)
|
||||||
|
|
||||||
async with connect(os.getenv("WEBSOCKET_ADDRESS")) as websocket:
|
# Start connection and get client connection protocol
|
||||||
while True:
|
client = await PlaceClient.connect(os.getenv(Environment.WEBSOCKET_ADDRESS))
|
||||||
print(websocket.messages)
|
client.current_target = original_image
|
||||||
|
asyncio.create_task(client.receive())
|
||||||
|
|
||||||
original_image = Image.open(source_path)
|
# await asyncio.sleep(2)
|
||||||
original_image = original_image.resize((width, height), Image.LANCZOS)
|
await client.complete(5)
|
||||||
|
|
||||||
source = await get_image(websocket)
|
print('Complete.')
|
||||||
ips = get_pixel_differences(source, original_image)
|
|
||||||
|
|
||||||
upload(ips)
|
return
|
||||||
|
|
||||||
if len(ips) < 5:
|
|
||||||
break
|
|
||||||
|
|
||||||
original_image.close()
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user