-
-
Save chtnnh/601437d7ff324b5c7484c1c5ba9266b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mwparsefromhell | |
example = """ | |
{{foo bar baz}} | |
{{I am a random template}} | |
{{Marca de projeto|3|Biografias|4|Políticos|4|Brasil|3|WP Offline|2|bot=4/20111127|rev=20170714}}""" | |
templates = list(mwparserfromhell.parse(example_text).filter_templates()) | |
def from_template(template): | |
"Returns an iterator of projects and classes from a template if applicable" | |
WP_PREFIX = re.compile("\{\{marca de projeto\|[0-9*]\|([a-z]*\|[0-9*])+\}\}", re.I) | |
return wP_PREFIX.sub('', template.name.lower().replace("_", " ")).strip() | |
for template in templates: | |
print(list(from_template(template))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] | |
[] | |
[("Biographias", "4"), ("Políticos", "4"), ("Brasil", "3"), ("WP Offline", "2")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment