-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (31 loc) · 1020 Bytes
/
app.py
File metadata and controls
39 lines (31 loc) · 1020 Bytes
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
import requests
import pygame
import config
import app_settings
pygame.init()
screen = pygame.display.set_mode(app_settings.WND_SIZE)
pygame.display.set_caption(app_settings.WND_NAME)
current_image = None
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
image_id = int(input()) # todo input from app (not from terminal)
r_json = {'id': image_id}
response = requests.post(config.SERVER_URL, json=r_json)
if response.status_code == 200:
with open('received_image.png', 'wb') as f:
f.write(response.content)
print('Image received and saved.')
current_image = pygame.image.load('received_image.png')
current_image = pygame.transform.scale(
current_image,
app_settings.WND_SIZE
)
else:
print('Error:', response.json())
if current_image:
screen.blit(current_image, (0, 0))
pygame.display.flip()
pygame.quit()