User:Verilux
Appearance
|
Guides
[edit]Wikipedia:UNIGUIDE
WP:MOSINTRO
Template scripts
[edit]Infobox university rankings/doc
[edit]The following Python script generates an updated demonstration box for use in Template:Infobox university rankings/doc.
#!/bin/python
# Generates a demonstration box for "Template:Infobox university rankings/doc"
import urllib.request, re
# Fetch template code
with urllib.request.urlopen('https://en.wikipedia.org/w/api.php?action=parse' +
'&page=Template:Infobox_university_rankings&' +
'prop=wikitext') as response:
template_code = response.read().decode()
# Isolate ranking tags; a tag may only include letters, numbers, and underscores
data_lines = re.findall('[|]{1}\s*data\d+\s*=\s*[{]{3}\w+[|]{1}', template_code)
# Print out updated sample box
print('{{Infobox university rankings')
print('| name = name')
for data_line in data_lines:
tag = data_line.split('{{{')[1].split('|')[0]
print('| ' + tag + ' = ' + tag + ' | ' + tag + '_ref = ‌')
print('}}')