Skip to content

Instantly share code, notes, and snippets.

@halfak
Last active March 12, 2020 20:16
Show Gist options
  • Save halfak/d6efaa43376a6b190b0dbeb15a906dd7 to your computer and use it in GitHub Desktop.
Save halfak/d6efaa43376a6b190b0dbeb15a906dd7 to your computer and use it in GitHub Desktop.
import mwparsefromhell
example = """
{{foo bar baz}}
{{I am a random template|7|Foo bar|8}}
{{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"
pass
for template in templates:
print(list(from_template(template)))
[]
[]
[("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