kopia lustrzana https://github.com/glidernet/ogn-python
Fixed get_country_code
rodzic
e20e886952
commit
8fa4f16a96
|
@ -42,5 +42,8 @@ def get_ddb(csvfile=None):
|
||||||
def get_country_code(latitude, longitude):
|
def get_country_code(latitude, longitude):
|
||||||
geolocator = Nominatim()
|
geolocator = Nominatim()
|
||||||
location = geolocator.reverse("%f, %f" % (latitude, longitude))
|
location = geolocator.reverse("%f, %f" % (latitude, longitude))
|
||||||
country_code = location.raw["address"]["country_code"]
|
try:
|
||||||
|
country_code = location.raw["address"]["country_code"]
|
||||||
|
except KeyError:
|
||||||
|
country_code = None
|
||||||
return country_code
|
return country_code
|
||||||
|
|
|
@ -27,3 +27,9 @@ class TestStringMethods(unittest.TestCase):
|
||||||
longitude = 11.0
|
longitude = 11.0
|
||||||
country_code = get_country_code(latitude, longitude)
|
country_code = get_country_code(latitude, longitude)
|
||||||
self.assertEquals(country_code, 'de')
|
self.assertEquals(country_code, 'de')
|
||||||
|
|
||||||
|
def test_get_country_code_bad(self):
|
||||||
|
latitude = 0.0002274
|
||||||
|
longitude = -0.0009119
|
||||||
|
country_code = get_country_code(latitude, longitude)
|
||||||
|
self.assertEqual(country_code, None)
|
||||||
|
|
Ładowanie…
Reference in New Issue