From 57984df95b02259e2765773eaac58d9b9396dc0d Mon Sep 17 00:00:00 2001 From: Egor Deev <67710823+IGlek@users.noreply.github.com> Date: Sat, 19 Mar 2022 18:48:17 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Полный поиск/delta.py | 21 +++++++++++++++ Полный поиск/main.py | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Полный поиск/delta.py create mode 100644 Полный поиск/main.py diff --git a/Полный поиск/delta.py b/Полный поиск/delta.py new file mode 100644 index 0000000..964a076 --- /dev/null +++ b/Полный поиск/delta.py @@ -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)) \ No newline at end of file diff --git a/Полный поиск/main.py b/Полный поиск/main.py new file mode 100644 index 0000000..70a1a5f --- /dev/null +++ b/Полный поиск/main.py @@ -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() \ No newline at end of file