diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 16:20:40 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 16:20:40 +0200 |
commit | 1b8c98823a4ba7029065a06efdd849382ac8b15c (patch) | |
tree | f95964e95027115cd79b45767ad23517c60a5bec | |
parent | ddb780ea97386352196718ea250c120fbfae3ec5 (diff) | |
download | wikimini-1b8c98823a4ba7029065a06efdd849382ac8b15c.tar.gz wikimini-1b8c98823a4ba7029065a06efdd849382ac8b15c.tar.bz2 wikimini-1b8c98823a4ba7029065a06efdd849382ac8b15c.zip |
Retrieve title as well
-rw-r--r-- | wikimini/__init__.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/wikimini/__init__.py b/wikimini/__init__.py index 7dc573e..ca8bfab 100644 --- a/wikimini/__init__.py +++ b/wikimini/__init__.py @@ -17,7 +17,7 @@ def page_url(title): return title.replace(" ", "_") -def retrieve(title: str) -> mwp.wikicode.Wikicode: +def retrieve(title: str) -> (str, mwp.wikicode.Wikicode): params = { "action": "query", "prop": "revisions", @@ -31,9 +31,11 @@ def retrieve(title: str) -> mwp.wikicode.Wikicode: headers = {"User-Agent": "Wikimini/1.0"} req = requests.get(API_URL, headers=headers, params=params) res = req.json() - revision = res["query"]["pages"][0]["revisions"][0] + page = res["query"]["pages"][0] + title = page["title"] + revision = page["revisions"][0] text = revision["slots"]["main"]["content"] - return mwp.parse(text) + return (title, mwp.parse(text)) def render_convert(obj: mwp.nodes.template.Template) -> str: @@ -178,10 +180,17 @@ def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: return render_convert(obj) elif name in {"lang", "script"}: return _convert(obj.params[1].value) + elif name == "lang-ar": + return "Arabic {}/{}".format( + _convert(obj.params[0].value), + _convert(obj.params[1].value), + ) elif name in {"reign", "r.", "ruled", "rexit"}: return render_reign(obj) elif name in {"cite book", "cite journal", "cite news"}: return render_cite_book(obj) + elif name.startswith("ipa"): + return "pronounced [{}]".format(_convert(obj.params[0].value)) elif name == "main": return render_main(obj) else: |