class TestAPI(unittest.TestCase): def setUp(self) -> None: self.api = Api(os.environ.get('POSTCODE_API_KEY')) self.api.url = 'https://sandbox.postcodeapi.nu' def test_api_key_is_required(self): with self.assertRaises(pyPostcodeException): Api('') def test_api(self): results = self.api.getaddress('6545CA', 29) latitude = 51.841554 longitude = 5.8696099 self.assertEqual(results.postcode, '6545CA') self.assertEqual(results.house_number, 29) self.assertEqual(results.street, 'Waldeck Pyrmontsingel') self.assertEqual(results.city, 'Nijmegen') self.assertEqual(results.municipality, 'Nijmegen') self.assertEqual(results.province, 'Gelderland') self.assertEqual(results.coordinates, [longitude, latitude]) self.assertEqual(results.x, longitude) self.assertEqual(results.longitude, longitude) self.assertEqual(results.y, latitude) self.assertEqual(results.latitude, latitude)
def get_provider_obj(self): apikey = self.env['ir.config_parameter'].get_param( 'l10n_nl_postcodeapi.apikey', '').strip() if not apikey or apikey == 'Your API key': return False from pyPostcode import Api provider = Api(apikey, (2, 0, 0)) test = provider.getaddress('1053NJ', '334T') if not test or not test._data: raise exceptions.Warning( _('Could not verify the connection with the address ' 'lookup service (if you want to get rid of this ' 'message, please rename or delete the system parameter ' '\'l10n_nl_postcodeapi.apikey\').')) return provider
from pyPostcode import Api postcodeapi = Api('{YOUR_API_KEY}') result_street = postcodeapi.getaddress('1011AC') # use p6 search result_address = postcodeapi.getaddress('1011AC', 154) # use address search for result in [result_street, result_address]: print result.street print result.house_number print result.postcode print result.town print result.municipality print result.province print result.latitude print result.longitude print result.x print result.y
from pyPostcode import Api postcodeapi = Api('{YOUR_API_KEY}') result_street = postcodeapi.getaddress('1011AC') # use p6 search result_address = postcodeapi.getaddress('1011AC', 154) # use address search print result_street._data, result_address._data
from pyPostcode import Api postcodeapi = Api('{YOUR_API_KEY}') result = postcodeapi.getaddress('1011AC', 154) # use address search print(result.street) print(result.house_number) print(result.postcode) print(result.town) print(result.municipality) print(result.province)