Skip to content

Commit

Permalink
Use wikiReader in TagWatchFrViPofm
Browse files Browse the repository at this point in the history
  • Loading branch information
Famlam committed Oct 14, 2024
1 parent 98c198a commit 5e2ae36
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions plugins/TagWatchFrViPofm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from modules.Stablehash import stablehash, stablehash64
import re
from collections import defaultdict
from plugins.modules.wikiReader import read_wiki_table, wikitag2text


class TagWatchFrViPofm(Plugin):
Expand Down Expand Up @@ -52,43 +53,43 @@ def init(self, logger):
self._update_ks_vr = defaultdict(dict)
self._update_kr_vr = defaultdict(dict)

reline = re.compile(r"^\|([^|]*)\|\|([^|]*)\|\|([^|]*)\|\|([^|]*).*")

# Obtain the info from https://wiki.openstreetmap.org/index.php?title=Tagging_mistakes
data = urlread(u"https://wiki.openstreetmap.org/index.php?title=Tagging_mistakes&action=raw", 1)
data = data.split("\n")
for line in data:
for res in reline.findall(line):
only_for = res[3].strip()
if only_for in (None, '', country, language) or (country and country.startswith(only_for)):
r = res[1].strip()
c0 = res[2].strip()
tags = ["fix:chair"] if c0 == "" else [c0, "fix:chair"]
c = stablehash(c0)
self.errors[c] = self.def_class(item = 3030, level = 2, tags = tags,
title = {'en': c0},
detail = T_(
data = read_wiki_table(data, skip_headers = False)[1:] # Headers in the middle of the table, not supported yet in read_wiki_table

for row in data:
only_for = row[3]
if only_for in (None, '', country, language) or (country and country.startswith(only_for)) or only_for.lower().startswith("{{taginfo"): # This also filters out the alphabetical headers
r = wikitag2text(row[1]) # replace-value
f = wikitag2text(row[0]) # to-be-replaced value
c0 = row[2] # the Osmose issue tag and issue title
tags = ["fix:chair"] if c0 == "" else [c0, "fix:chair"]
c = stablehash(c0)
self.errors[c] = self.def_class(item = 3030, level = 2, tags = tags,
title = {'en': c0},
detail = T_(
'''Simple and frequent errors, can be updated by anyone on the wiki.'''),
resource = 'https://wiki.openstreetmap.org/wiki/Tagging_mistakes')
if u"=" in res[0]:
k = res[0].split(u"=")[0].strip()
v = res[0].split(u"=")[1].strip()
if self.quoted(k):
k = self.quoted2re(k)
if self.quoted(v):
self._update_kr_vr[k][self.quoted2re(v)] = [r, c]
else:
self._update_kr_vs[k][v] = [r, c]
resource = 'https://wiki.openstreetmap.org/wiki/Tagging_mistakes')

if "=" in f:
k = f.split("=")[0].strip()
v = f.split("=")[1].strip()
if self.quoted(k):
k = self.quoted2re(k)
if self.quoted(v):
self._update_kr_vr[k][self.quoted2re(v)] = [r, c]
else:
if self.quoted(v):
self._update_ks_vr[k][self.quoted2re(v)] = [r, c]
else:
self._update_ks_vs[k][v] = [r, c]
self._update_kr_vs[k][v] = [r, c]
else:
if self.quoted(res[0]):
self._update_kr[self.quoted2re(res[0])] = [r, c]
if self.quoted(v):
self._update_ks_vr[k][self.quoted2re(v)] = [r, c]
else:
self._update_ks[res[0]] = [r, c]
self._update_ks_vs[k][v] = [r, c]
else:
if self.quoted(f):
self._update_kr[self.quoted2re(f)] = [r, c]
else:
self._update_ks[f] = [r, c]

def node(self, data, tags):
err = []
Expand Down

0 comments on commit 5e2ae36

Please sign in to comment.