Merge pull request #2 from Meisterschueler/better_scheme

Fixed get_country_code and changed scheme
pull/1/head
Meisterschueler 2015-11-12 08:44:35 +01:00
commit 0203ab00af
2 zmienionych plików z 10 dodań i 1 usunięć

Wyświetl plik

@ -42,5 +42,8 @@ def get_ddb(csvfile=None):
def get_country_code(latitude, longitude):
geolocator = Nominatim()
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

Wyświetl plik

@ -27,3 +27,9 @@ class TestStringMethods(unittest.TestCase):
longitude = 11.0
country_code = get_country_code(latitude, longitude)
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)