File tree Expand file tree Collapse file tree 3 files changed +23
-11
lines changed
Expand file tree Collapse file tree 3 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,7 @@ pip install .
275275
276276## Version History
277277
278+ * 0.5.8: Updated address and placename data. Added municipality name data to address records. Now requires Python 3.9+ (27/02/2025)
278279* 0.5.7: Updated address and placename data. Now requires Python 3.8+ (20/09/2024)
279280* 0.5.6: Updated address and placename data (11/08/2023)
280281* 0.5.5: Updated address and placename data. Removed ISN93 coords. Now requires Python 3.7+ (11/12/2022)
Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22"""
33
4- Fetch list of postcodes from the Icelandic postal service,
5- create and print dict mapping postcode to placename and
6- other related information. Also adds placenames in the
7- nominative case (nefnifall) since the source data only
8- includes placenames in dative (þágufall).
4+ Fetch list of postcodes from the Icelandic postal service,
5+ create and print dict mapping postcode to placename and
6+ other related information. Also adds placenames in the
7+ nominative case (nefnifall) since the source data only
8+ includes placenames in dative (þágufall).
99
10- https://www.postur.is/gogn/Gotuskra/postnumer.txt
10+ https://www.postur.is/gogn/Gotuskra/postnumer.txt
1111
1212"""
1313
14- import requests
15- import pprint
16- import logging
1714import csv
15+ import logging
16+ import pprint
1817from io import StringIO
1918
19+ import requests
2020from reynir import NounPhrase
2121
2222from iceaddr .postcodes import POSTCODES
2323
24-
2524POSTCODES_REMOTE_URL = "https://www.postur.is/gogn/Gotuskra/postnumer.txt"
2625
2726
@@ -34,7 +33,7 @@ def main() -> None:
3433 pc_keys = pc .keys ()
3534 pp = pprint .PrettyPrinter (indent = 4 )
3635
37- req = requests .get (POSTCODES_REMOTE_URL , allow_redirects = True )
36+ req = requests .get (POSTCODES_REMOTE_URL , allow_redirects = True , timeout = 10 )
3837 f = StringIO (req .text )
3938
4039 changed = False
Original file line number Diff line number Diff line change 2121 POSTCODES ,
2222 iceaddr_lookup ,
2323 iceaddr_suggest ,
24+ municipality_code_for_municipality ,
25+ municipality_for_municipality_code ,
2426 nearest_addr ,
2527 nearest_placenames ,
2628 postcode_lookup ,
@@ -97,6 +99,9 @@ def test_address_suggestions():
9799 assert res [0 ]["heiti_nf" ] == "Öldugata"
98100 assert res [0 ]["husnr" ] == 4
99101 assert res [0 ]["stadur_nf" ] == "Reykjavík"
102+ assert res [0 ]["postnr" ] == 101
103+ assert res [0 ]["svaedi_nf" ] == "Höfuðborgarsvæðið"
104+ assert res [0 ]["svfheiti" ] == "Reykjavíkurborg"
100105
101106 res = iceaddr_suggest ("Öldugata 4, Rey" )
102107 assert [n ["stadur_tgf" ] for n in res ] == ["Reykjavík" , "Reyðarfirði" ]
@@ -161,6 +166,13 @@ def test_postcode_lookup():
161166 assert postcodes_for_region ("Höfuðborgarsvæðið" )
162167
163168
169+ def test_municipality_lookup ():
170+ """Test municipality code lookup functions."""
171+ assert municipality_code_for_municipality ("Reykjavíkurborg" ) == 0
172+
173+ assert municipality_for_municipality_code (0 ) == "Reykjavíkurborg"
174+
175+
164176FISKISLOD_31_COORDS = (64.1560233 , - 21.951407 )
165177OLDUGATA_4_COORDS = (64.148446 , - 21.944933 )
166178POSTCODE_101 = 101
You can’t perform that action at this time.
0 commit comments