yandex_lyceum/Полный поиск/main.py
2022-03-19 18:48:17 +07:00

45 lines
No EOL
1.1 KiB
Python

from io import BytesIO
from PIL import Image
from delta import delta
import requests
search_api_server = "https://search-maps.yandex.ru/v1/"
api_key = "dda3ddba-c9ea-4ead-9010-f43fbc15c6e3"
address_ll = "37.588392,55.734036"
search_params = {
"apikey": api_key,
"text": "магазин",
"lang": "ru_RU",
"ll": address_ll,
"type": "biz"
}
response = requests.get(search_api_server, params=search_params)
if not response:
pass
json_response = response.json()
organization = json_response["features"][0]
org_name = organization["properties"]["CompanyMetaData"]["name"]
org_address = organization["properties"]["CompanyMetaData"]["address"]
point = organization["geometry"]["coordinates"]
org_point = "{0},{1}".format(point[0], point[1])
delta = delta(point, address_ll)
map_params = {
"ll": address_ll,
"spn": ",".join([delta, delta]),
"l": "map",
"pt": "{0},pm2dgl".format(org_point)
}
map_api_server = "http://static-maps.yandex.ru/1.x/"
response = requests.get(map_api_server, params=map_params)
Image.open(BytesIO(
response.content)).show()