-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a413b68
commit 82e6076
Showing
10 changed files
with
306 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Yandex | ||
|
||
Yandex (Russian: Яндекс) is a Russian Internet company | ||
which operates the largest search engine in Russia with | ||
about 60% market share in that country. | ||
|
||
The Yandex home page has been rated as the most popular website in Russia. | ||
|
||
## Examples | ||
|
||
**Standard Geocoding** | ||
|
||
```python | ||
>>> import geocoder | ||
>>> g = geocoder.yandex('Moscow Russia') | ||
>>> g.json | ||
... | ||
``` | ||
|
||
**Reverse Geocoding** | ||
|
||
```python | ||
>>> import geocoder | ||
>>> g = geocoder.yandex([45.15, -75.14], method='reverse') | ||
>>> g.json | ||
... | ||
``` | ||
|
||
**Command Line Interface** | ||
|
||
```bash | ||
$ geocode 'embedded.fizzled.trial' --provider w3w | ||
$ geocode '45.15, -75.14' --provider w3w --method reverse | ||
``` | ||
|
||
## Parameters | ||
|
||
- `location`: Your search location you want geocoded. | ||
- `lang`: Chose the following language: | ||
* `ru-RU` — Russian (by default) | ||
* `uk-UA` — Ukrainian | ||
* `be-BY` — Belarusian | ||
* `en-US` — American English | ||
* `en-BR` — British English | ||
* `tr-TR` — Turkish (only for maps of Turkey) | ||
- `kind`: Type of toponym (only for reverse geocoding): | ||
* `house` - house or building | ||
* `street` - street | ||
* `metro` - subway station | ||
* `district` - city district | ||
* `locality` - locality (city, town, village, etc.) | ||
|
||
## References | ||
|
||
- [API Reference](http://api.yandex.com/maps/doc/geocoder/desc/concepts/input_params.xml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/python | ||
# coding: utf8 | ||
|
||
from .base import Base | ||
|
||
|
||
class Yandex(Base): | ||
""" | ||
Yandex | ||
====== | ||
Yandex (Russian: Яндекс) is a Russian Internet company | ||
which operates the largest search engine in Russia with | ||
about 60% market share in that country. | ||
The Yandex home page has been rated as the most popular website in Russia. | ||
Params | ||
------ | ||
:param location: Your search location you want geocoded. | ||
:param lang: Chose the following language: | ||
> ru-RU — Russian (by default) | ||
> uk-UA — Ukrainian | ||
> be-BY — Belarusian | ||
> en-US — American English | ||
> en-BR — British English | ||
> tr-TR — Turkish (only for maps of Turkey) | ||
:param kind: Type of toponym (only for reverse geocoding): | ||
> house - house or building | ||
> street - street | ||
> metro - subway station | ||
> district - city district | ||
> locality - locality (city, town, village, etc.) | ||
References | ||
---------- | ||
API Reference: http://api.yandex.com/maps/doc/geocoder/ | ||
desc/concepts/input_params.xml | ||
""" | ||
provider = 'yandex' | ||
method = 'geocode' | ||
|
||
def __init__(self, location, **kwargs): | ||
self.url = 'http://geocode-maps.yandex.ru/1.x/' | ||
self.location = location | ||
self.params = { | ||
'geocode': location, | ||
'lang': kwargs.get('lang', 'en-US'), | ||
'kind': kwargs.get('kind', ''), | ||
'format': 'json', | ||
'results': 1, | ||
} | ||
self._initialize(**kwargs) | ||
|
||
def _exceptions(self): | ||
# Build intial Tree with results | ||
feature = self.parse['GeoObjectCollection']['featureMember'] | ||
for item in feature: | ||
self._build_tree(item['GeoObject']) | ||
|
||
@property | ||
def address(self): | ||
return self.parse['GeocoderMetaData'].get('text') | ||
|
||
@property | ||
def lat(self): | ||
pos = self.parse['Point'].get('pos') | ||
if pos: | ||
return pos.split(' ')[1] | ||
|
||
@property | ||
def lng(self): | ||
pos = self.parse['Point'].get('pos') | ||
if pos: | ||
return pos.split(' ')[0] | ||
|
||
@property | ||
def bbox(self): | ||
if self.parse['Envelope']: | ||
east, north = self.parse['Envelope'].get('upperCorner').split(' ') | ||
west, south = self.parse['Envelope'].get('lowerCorner').split(' ') | ||
return self._get_bbox(south, west, north, east) | ||
|
||
@property | ||
def quality(self): | ||
return self.parse['GeocoderMetaData'].get('kind') | ||
|
||
@property | ||
def accuracy(self): | ||
return self.parse['GeocoderMetaData'].get('precision') | ||
|
||
@property | ||
def housenumber(self): | ||
return self.parse['Premise'].get('PremiseNumber') | ||
|
||
@property | ||
def street(self): | ||
return self.parse['Thoroughfare'].get('ThoroughfareName') | ||
|
||
@property | ||
def city(self): | ||
return self.parse['Locality'].get('LocalityName') | ||
|
||
@property | ||
def county(self): | ||
return self.parse['SubAdministrativeArea'].get('SubAdministrative' | ||
'AreaName') | ||
|
||
@property | ||
def state(self): | ||
return self.parse['AdministrativeArea'].get('AdministrativeAreaName') | ||
|
||
@property | ||
def country(self): | ||
return self.parse['Country'].get('CountryName') | ||
|
||
@property | ||
def country_code(self): | ||
return self.parse['Country'].get('CountryNameCode') | ||
|
||
|
||
if __name__ == '__main__': | ||
g = Yandex('-75.501846, 45.481158') | ||
import json | ||
print(json.dumps(g.json, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/python | ||
# coding: utf8 | ||
|
||
from .base import Base | ||
from .yandex import Yandex | ||
from .location import Location | ||
|
||
|
||
class YandexReverse(Yandex, Base): | ||
""" | ||
Yandex | ||
====== | ||
Yandex (Russian: Яндекс) is a Russian Internet company | ||
which operates the largest search engine in Russia with | ||
about 60% market share in that country. | ||
The Yandex home page has been rated as the most popular website in Russia. | ||
Params | ||
------ | ||
:param location: Your search location you want geocoded. | ||
:param lang: Chose the following language: | ||
> ru-RU — Russian (by default) | ||
> uk-UA — Ukrainian | ||
> be-BY — Belarusian | ||
> en-US — American English | ||
> en-BR — British English | ||
> tr-TR — Turkish (only for maps of Turkey) | ||
:param kind: Type of toponym (only for reverse geocoding): | ||
> house - house or building | ||
> street - street | ||
> metro - subway station | ||
> district - city district | ||
> locality - locality (city, town, village, etc.) | ||
References | ||
---------- | ||
API Reference: http://api.yandex.com/maps/doc/geocoder/ | ||
desc/concepts/input_params.xml | ||
""" | ||
provider = 'yandex' | ||
method = 'reverse' | ||
|
||
def __init__(self, location, **kwargs): | ||
self.url = 'http://geocode-maps.yandex.ru/1.x/' | ||
location = Location(location) | ||
self.location = location.xy | ||
self.params = { | ||
'geocode': self.location, | ||
'lang': kwargs.get('lang', 'en-US'), | ||
'kind': kwargs.get('kind', ''), | ||
'format': 'json', | ||
'results': 1, | ||
} | ||
self._initialize(**kwargs) | ||
|
||
@property | ||
def ok(self): | ||
return bool(self.address) | ||
|
||
|
||
if __name__ == '__main__': | ||
g = Yandex('-75.501846, 45.481158') | ||
import json | ||
print(json.dumps(g.json, indent=2)) |
Oops, something went wrong.