A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

integration.rst 1.3 KiB

1234567891011121314151617181920212223242526272829303132333435
  1. Integration
  2. ===========
  3. :py:mod:`mwparserfromhell` is used by and originally developed for EarwigBot_;
  4. :py:class:`~earwigbot.wiki.page.Page` objects have a
  5. :py:meth:`~earwigbot.wiki.page.Page.parse` method that essentially calls
  6. :py:func:`mwparserfromhell.parse() <mwparserfromhell.__init__.parse>` on
  7. :py:meth:`~earwigbot.wiki.page.Page.get`.
  8. If you're using Pywikipedia_, your code might look like this::
  9. import mwparserfromhell
  10. import wikipedia as pywikibot
  11. def parse(title):
  12. site = pywikibot.getSite()
  13. page = pywikibot.Page(site, title)
  14. text = page.get()
  15. return mwparserfromhell.parse(text)
  16. If you're not using a library, you can parse templates in any page using the
  17. following code (via the API_)::
  18. import json
  19. import urllib
  20. import mwparserfromhell
  21. API_URL = "http://en.wikipedia.org/w/api.php"
  22. def parse(title):
  23. raw = urllib.urlopen(API_URL, data).read()
  24. res = json.loads(raw)
  25. text = res["query"]["pages"].values()[0]["revisions"][0]["*"]
  26. return mwparserfromhell.parse(text)
  27. .. _EarwigBot: https://github.com/earwig/earwigbot
  28. .. _Pywikipedia: https://www.mediawiki.org/wiki/Manual:Pywikipediabot
  29. .. _API: http://mediawiki.org/wiki/API