-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (33 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from dotenv import load_dotenv
load_dotenv()
import asyncio
import io
import os
from PIL import Image
from place.client import PlaceClient
from place.constants import Environment
# Start a websocket
# In the initial image load, detect all changes between the target and
async def get_image(websocket):
while True:
data = await websocket.recv()
if type(data) == bytes:
return Image.open(io.BytesIO(data))
async def main():
# 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)
# Start connection and get client connection protocol
client = await PlaceClient.connect(os.getenv(Environment.WEBSOCKET_ADDRESS))
client.current_target = original_image
asyncio.create_task(client.receive())
await asyncio.sleep(0.8)
async with client.lock():
client.source.save("./x.png")
client.current_target.save("./target.png")
await client.complete(1)
print('Complete.')
return
if __name__ == "__main__":
asyncio.run(main())