]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/lib.title.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / lib.title.py
1 """
2 Demonstrates title normalization and parsing.
3 """
4 import sys
5 import os
6
7 sys.path.insert(0, os.path.abspath(os.getcwd()))
8
9 from mw.api import Session
10 from mw.lib import title
11
12 # Normalize titles
13 title.normalize("foo bar")
14 # > "Foo_bar"
15
16 # Construct a title parser from the API
17 api_session = Session("https://en.wikipedia.org/w/api.php")
18 parser = title.Parser.from_api(api_session)
19
20 # Handles normalization
21 parser.parse("user:epochFail")
22 # > 2, "EpochFail"
23
24 # Handles namespace aliases
25 parser.parse("WT:foobar")
26 # > 5, "Foobar"

Community Data Science Collective || Want to submit a patch?