mirror of
https://github.com/EDeev/yandex_lyceum.git
synced 2026-06-15 11:01:04 +03:00
Полный поиск
This commit is contained in:
commit
57984df95b
2 changed files with 66 additions and 0 deletions
21
Полный поиск/delta.py
Normal file
21
Полный поиск/delta.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
def delta(org, adr):
|
||||
first = "0.0001"
|
||||
adr = list(map(float, adr.split(',')))
|
||||
|
||||
k1 = float(first)
|
||||
while True:
|
||||
k = adr[0] + k1
|
||||
if org[0] + 0.001 >= k:
|
||||
k1 *= 10
|
||||
else:
|
||||
break
|
||||
|
||||
k2 = float(first)
|
||||
while True:
|
||||
k = adr[1] + k2
|
||||
if org[1] + 0.001 >= k:
|
||||
k2 *= 10
|
||||
else:
|
||||
break
|
||||
|
||||
return str(max(k1, k2))
|
||||
45
Полный поиск/main.py
Normal file
45
Полный поиск/main.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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()
|
||||
Loading…
Add table
Reference in a new issue