├── requirements.txt ├── yandex_maps ├── __init__.py ├── exceptions.py └── yandex_maps.py ├── setup.py ├── README.md ├── .github └── workflows │ └── pythonapp.yml └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | -------------------------------------------------------------------------------- /yandex_maps/__init__.py: -------------------------------------------------------------------------------- 1 | from yandex_maps.yandex_maps import Yandexmaps -------------------------------------------------------------------------------- /yandex_maps/exceptions.py: -------------------------------------------------------------------------------- 1 | class YandexmapsException(Exception): 2 | pass 3 | 4 | 5 | class YandexmapsLocationNotFoundException(YandexmapsException): 6 | pass 7 | 8 | 9 | class YandexmapsAddressNotFoundException(YandexmapsException): 10 | pass 11 | 12 | class YandexmapsInvalidApiKeyException(YandexmapsException): 13 | pass -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="Yandexmaps", 8 | version="0.3", 9 | author="Sadullyev Behzod", 10 | author_email="begymrx@gmail.com", 11 | description=long_description, 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/begyy/Yandexmaps", 15 | packages=setuptools.find_packages(), 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "License :: OSI Approved :: MIT License", 19 | "Operating System :: OS Independent", 20 | ], 21 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yandexmaps 2 | [![Downloads](https://pepy.tech/badge/yandexmaps)](https://pepy.tech/project/yandexmaps) 3 | ![Python application](https://github.com/begyy/Yandexmaps/workflows/Python%20application/badge.svg) 4 | ```` 5 | pip install requests 6 | pip install yandexmaps 7 | ```` 8 | 9 | # Example 10 | 11 | ``` 12 | from yandex_maps import Yandexmaps 13 | yandex = Yandexmaps() 14 | yandex.address('Узбекистан, Ташкент, сквер Амира Темура') 15 | >>> ('69.279737', '41.311273') 16 | 17 | yandex.locations(longitude='69.279737', latitude='41.311273') 18 | >>> Oʻzbekiston, Toshkent, Amir Temur xiyoboni 19 | ``` 20 | 21 | ``` 22 | from yandex_maps import Yandexmaps 23 | Yandexmaps(language='ru_RU',api_key='token').locations(longitude='69.279737', latitude='41.311273') 24 | >>> Узбекистан, Ташкент, сквер Амира Темура 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /.github/workflows/pythonapp.yml: -------------------------------------------------------------------------------- 1 | name: Python application 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up Python 3.7 13 | uses: actions/setup-python@v1 14 | with: 15 | python-version: 3.7 16 | - name: Install dependencies 17 | run: | 18 | python -m pip install --upgrade pip 19 | pip install -r requirements.txt 20 | - name: Lint with flake8 21 | run: | 22 | pip install flake8 23 | # stop the build if there are Python syntax errors or undefined names 24 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 25 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 26 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 27 | # - name: Test with pytest 28 | # run: | 29 | # pip install pytest 30 | # pytest 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 The Python Packaging Authority 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /yandex_maps/yandex_maps.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from yandex_maps.exceptions import ( 3 | YandexmapsAddressNotFoundException, 4 | YandexmapsLocationNotFoundException, 5 | YandexmapsInvalidApiKeyException 6 | ) 7 | 8 | 9 | class Yandexmaps: 10 | def __init__(self, api_key=None, format='json', language='uz_UZ'): 11 | ''' 12 | 13 | :param api_key: 14 | :param format: 15 | :param language: 16 | ''' 17 | self.api_url = "https://geocode-maps.yandex.ru/1.x/" 18 | self.api_key = api_key 19 | self.format = format 20 | self.language = language 21 | 22 | def locations(self, longitude: str, latitude: str): 23 | ''' 24 | 25 | :param longitude: 26 | :param latitude: 27 | :return: Узбекистан, Ташкент, сквер Амира Темура 28 | ''' 29 | location = '{},{}'.format(longitude, latitude) 30 | data = self.request(data=location)["GeoObjectCollection"]["featureMember"] 31 | 32 | if not data: 33 | raise YandexmapsLocationNotFoundException( 34 | '"{},{}" not found'.format(longitude, latitude) 35 | ) 36 | 37 | return data[0]["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["text"] 38 | 39 | def address(self, address: str): 40 | ''' 41 | 42 | :param address: 43 | :return: ('69.279737', '41.311273') 44 | ''' 45 | data = self.request(data=address)["GeoObjectCollection"]["featureMember"] 46 | 47 | if not data: 48 | raise YandexmapsAddressNotFoundException( 49 | '"{}" not found'.format(address) 50 | ) 51 | 52 | coordinates = data[0]["GeoObject"]["Point"]["pos"] 53 | return tuple(coordinates.split(" ")) 54 | 55 | def request(self, data): 56 | response = requests.get( 57 | url=self.api_url, 58 | params=self.params(data) 59 | ) 60 | 61 | if 'error' in response.json(): 62 | raise YandexmapsInvalidApiKeyException( 63 | '"{}" invalid api key'.format(self.api_key) 64 | ) 65 | 66 | return response.json()["response"] 67 | 68 | def params(self, obj): 69 | data = dict( 70 | { 71 | 'format': self.format, 72 | 'geocode': obj, 73 | 'lang': self.language 74 | } 75 | ) 76 | if self.api_key is not None: 77 | data.update({'apikey': self.api_key}) 78 | return data 79 | --------------------------------------------------------------------------------