Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix postal code with ? in the format #2367

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/TagFix_Postcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TagFix_Postcode(Plugin):
not_for = ("EG") # Egypt is transitioning to a new format. At 2024-04-15 there were still 2.4M entries in OSM in the old format

def parse_format(self, reline, format):
format = format.replace('optionally ', '')
format = format.replace('optionally ', '').replace("\n", " ")
if format[-1] == ')':
format = map(lambda x: x.strip(), format[:-1].split('('))
elif ' or ' in format:
Expand All @@ -44,15 +44,15 @@ def parse_format(self, reline, format):
regexs = []
for f in format:
if reline.match(f):
regexs.append(f.replace(" ", "").replace("-", "").replace(".", "").replace("N", "[0-9]").replace("A", "[A-Z]").replace("CC", "(:?"+self.Country+")?"))
regexs.append(f.replace(" ", "").replace("-", "").replace(".", "").replace("N", "[0-9]").replace("A", "[A-Z]").replace("?", "[A-Z0-9]").replace("CC", "(:?"+self.Country+")?"))

if len(regexs) > 1:
return "^(("+(")|(".join(regexs))+"))$"
elif len(regexs) == 1:
return "^"+regexs[0]+"$"

def list_postcode(self):
reline = re.compile("^[-CAN ]+$")
reline = re.compile("^[-CAN ?]+$")
data = urlread(u"https://en.wikipedia.org/wiki/List_of_postal_codes?action=raw", 1)
data = read_wiki_table(data)

Expand Down Expand Up @@ -270,6 +270,8 @@ class father:
config = _config()
a.father = father()
a.init(None)
assert a.node(None, {"addr:postcode":"123"})
assert a.node(None, {"addr:postcode":"A123"})
assert not a.node(None, {"addr:postcode":"AB123"})
assert not a.node(None, {"addr:postcode":"AB1234"})
assert not a.node(None, {"addr:postcode":"AB12345"})
Loading