Skip to content

Commit 5974e10

Browse files
committed
Use wikiReader in TagFix_Deprecated
1 parent 0d172a1 commit 5974e10

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

plugins/TagFix_Deprecated.py

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from plugins.Plugin import Plugin
2424
from modules.downloader import urlread
2525
from modules.Stablehash import stablehash
26+
from plugins.modules.wikiReader import read_wiki_templates,wikitag2text
2627
import re
2728

2829

@@ -31,55 +32,35 @@ def deprecated_list(self):
3132
wikiRoot = 'https://wiki.openstreetmap.org/wiki'
3233
data = urlread(wikiRoot + '/Template:Deprecated_features?action=raw', 1)
3334

34-
# Tidy data up for processing
35-
# Eliminate wiki bold formatting
36-
data = data.replace("'''", "")
37-
3835
# Remove HTML newlines
36+
# https://github.com/5j9/wikitextparser/issues/140
3937
data = re.sub(r'<br\s*/>', ' ', data)
4038

4139
# Remove excess whitespace (also removes all newlines)
4240
data = " ".join(data.split())
4341

44-
# Eliminate any whitespace around pipe characters
45-
# This makes reading the template parameters simple
46-
data = re.sub(r'\s?\|\s?', '|', data)
47-
48-
# Eliminate templates to prevent unexpected pipe characters
49-
data = re.sub(r'{{{\s?lang\s?\|?\s?}}}', '', data, flags=re.I)
50-
# Tag template can take one or two params, with trailing | possible
51-
data = re.sub(
52-
r'{{(?:Tag|Key)\s?\|(.+?)\|?\s?}}',
53-
lambda x: '`{}`'.format(x.group(1).replace("||", "=").replace("|", "=")),
54-
data,
55-
flags=re.I
56-
)
57-
58-
# Resolve interwiki links now
59-
data = re.sub(
60-
r'\[\[(.+?)\]\]',
61-
lambda x: '[{}]({}/{})'.format(x.group(1), wikiRoot, x.group(1).replace(" ", "_")),
62-
data
63-
)
42+
data = read_wiki_templates(data, "Deprecated features/item")
6443

6544
deprecated = {}
66-
for feature in data.split(r'{{Deprecated features/item')[1:]:
67-
# Unaccounted for template present in this feature
68-
if r'{{' in feature:
69-
continue
70-
45+
for feature in data:
7146
src_key, src_val, dest = None, None, None
72-
for param in feature.split('|'):
47+
for param in feature[2:]:
48+
# Convert {{Tag|k|v}} to k=v
49+
param = wikitag2text(param, quote = True, star_value = False)
7350
if '=' not in param:
7451
continue
52+
if '{{' in param:
53+
# Unaccounted for template present in this feature
54+
src_key, src_val, dest = None, None, None
55+
break
7556

7657
k, v = param.split('=', 1)
77-
# k will always start with the param because we removed whitespace around | earlier
78-
if (k.rstrip() == 'dkey'):
58+
k = k.rstrip()
59+
if k == 'dkey':
7960
src_key = v
80-
elif (k.rstrip() == 'dvalue'):
61+
elif k == 'dvalue':
8162
src_val = v
82-
elif (k.rstrip() == 'suggestion'):
63+
elif k == 'suggestion':
8364
dest = v
8465

8566
# Sanity check in case formatting changes or something

0 commit comments

Comments
 (0)