-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapsAPI.py
More file actions
43 lines (37 loc) · 1.45 KB
/
mapsAPI.py
File metadata and controls
43 lines (37 loc) · 1.45 KB
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
import requests
from PIL import Image
def get_image(toponym_longitude, toponym_lattitude, delta='0.005', zoom=10, l='sat', pt=[]):
toponym_lattitude = str(toponym_lattitude)
toponym_longitude = str(toponym_longitude)
try:
map_params = {
"ll": ",".join([toponym_longitude, toponym_lattitude]),
"l": l
}
if zoom != -1:
map_params["z"] = zoom
else:
map_params["spn"] = ",".join([delta, delta])
if pt:
flag = []
for i in pt:
flag.append(i[0] + ',' + i[1] + ',' + 'flag')
map_params['pt'] = '~'.join(flag)
# -------------------------------------------------------- print('map_params are', map_params)
map_api_server = "http://static-maps.yandex.ru/1.x/"
pic = requests.get(map_api_server, params=map_params)
print('>> Image URL:', pic.url)
if pic.content and l != 'sat':
with open("main_image.png", 'wb') as f:
f.write(pic.content)
elif pic.content:
# ----------------------------------------print('select jpg format')
with open("main_image.jpg", 'wb') as f:
f.write(pic.content)
im1 = Image.open(r'main_image.jpg')
im1.save(r'main_image.png')
return True
return False
except Exception as e:
print('error at get_image, stack:', e)
return False