Skip to content

Commit de40178

Browse files
committed
Use wikiReader in TagFix_Deprecated
1 parent 0161a92 commit de40178

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

plugins/TagFix_Deprecated.py

Lines changed: 14 additions & 37 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,31 @@ 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-
38-
# Remove HTML newlines
39-
data = re.sub(r'<br\s*/>', ' ', data)
40-
4135
# Remove excess whitespace (also removes all newlines)
4236
data = " ".join(data.split())
4337

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-
)
38+
data = read_wiki_templates(data, "Deprecated features/item")
6439

6540
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-
41+
for feature in data:
7142
src_key, src_val, dest = None, None, None
72-
for param in feature.split('|'):
43+
for param in feature[2:]:
44+
# Convert {{Tag|k|v}} to k=v
45+
param = wikitag2text(param, quote = True, star_value = False)
7346
if '=' not in param:
7447
continue
48+
if '{{' in param:
49+
# Unaccounted for template present in this feature
50+
src_key, src_val, dest = None, None, None
51+
break
7552

7653
k, v = param.split('=', 1)
77-
# k will always start with the param because we removed whitespace around | earlier
78-
if (k.rstrip() == 'dkey'):
54+
k = k.rstrip()
55+
if k == 'dkey':
7956
src_key = v
80-
elif (k.rstrip() == 'dvalue'):
57+
elif k == 'dvalue':
8158
src_val = v
82-
elif (k.rstrip() == 'suggestion'):
59+
elif k == 'suggestion':
8360
dest = v
8461

8562
# Sanity check in case formatting changes or something

0 commit comments

Comments
 (0)