-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
64 lines (55 loc) · 2.07 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys
import pygame
import requests
from functions import get_ll_spn, get_coordinates, get_nearest_object, geocode
toponym_to_find = "Красноярск, ул. Ленина, 114"
map_api_server = "http://static-maps.yandex.ru/1.x/"
map_params = {
"ll": get_ll_spn(toponym_to_find)[0],
"spn": get_ll_spn(toponym_to_find)[1],
"l": "map"
}
def load_map(server, params, name):
response = requests.get(server, params)
if not response:
print("Ошибка выполнения запроса:")
print(server + params)
print("Http статус:", response.status_code, "(", response.reason, ")")
sys.exit(1)
map_file = name
with open(map_file, "wb") as file:
file.write(response.content)
pygame.init()
screen = pygame.display.set_mode((600, 450))
load_map(map_api_server, map_params, "map1.png")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
os.remove('map1.png')
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_0:
map_params = {
"ll": get_ll_spn(toponym_to_find)[0],
"spn": get_ll_spn(toponym_to_find)[1],
"l": "sat"
}
load_map(map_api_server, map_params, "map1.png")
elif event.key == pygame.K_1:
map_params = {
"ll": get_ll_spn(toponym_to_find)[0],
"spn": get_ll_spn(toponym_to_find)[1],
"l": "map"
}
load_map(map_api_server, map_params, "map1.png")
if event.key == pygame.K_2:
map_params = {
"ll": get_ll_spn(toponym_to_find)[0],
"spn": get_ll_spn(toponym_to_find)[1],
"l": "sat,trf,skl"
}
load_map(map_api_server, map_params, "map1.png")
screen.blit(pygame.image.load('map1.png'), (0, 0))
pygame.display.flip()