{ "info": { "author": "Dan Michael Hegg\u00f8", "author_email": "danmichaelo@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Text Processing :: Markup" ], "description": "mwtemplates\n==================\n\n.. image:: http://img.shields.io/travis/danmichaelo/mwtemplates.svg?style=flat\n :target: https://travis-ci.org/danmichaelo/mwtemplates\n :alt: Build status\n\n.. image:: http://img.shields.io/coveralls/danmichaelo/mwtemplates.svg?style=flat\n :target: https://coveralls.io/r/danmichaelo/mwtemplates\n :alt: Test coverage\n\n.. image:: https://pypip.in/version/mwtemplates/badge.svg?style=flat\n :target: https://pypi.python.org/pypi/mwtemplates/\n :alt: Latest Version\n\n.. image:: https://pypip.in/py_versions/mwtemplates/badge.svg?style=flat\n :target: https://pypi.python.org/pypi/mwtemplates/\n :alt: Supported Python versions\n\n.. image:: https://pypip.in/download/mwtemplates/badge.svg?period=month&style=flat\n :target: https://pypi.python.org/pypi/mwtemplates/\n :alt: Downloads\n\nmwtemplates is a MediaWiki wikitext template parser and editor, based on a Python rewrite of the MediaWiki preprocessorDOM.php.\nTested with python 2.7, 3.3, 3.4, 3.5\n\n\nInstallation\n-------------------\n\nThe package is on `PyPI `_, so you can install it\nusing `pip`, `easy_install` or similar:\n\n.. code-block:: console\n\n $ pip install -U mwtemplates\n\nOr you can grab the latest zip from `releases `_.\n\nIntroduction\n------------\n\nLet's start by importing `TemplateEditor` and giving it some wikitext to eat:\n\n.. code-block:: python\n\n >>> from mwtemplates import TemplateEditor\n >>> txt = u\"\"\"{{Infobox cheese\n ... | name = Mozzarella\n ... | protein = 7\n ... }}\n ... Mozzarella is a cheese\u2026{{tr}}\"\"\"\n >>> te = TemplateEditor(txt)\n\nFirst, we can see what templates the editor found in the text:\n\n.. code-block:: python\n\n >>> te.templates\n [, ]\n\nEach template is an instance of a `Template` class. Also notice that template names are normalized by upper-casing the first character. Now, we can try investigating the `Infobox cheese` template:\n\n.. code-block:: python\n\n >>> te.templates['Infobox cheese']\n []\n\nSince there can be several instances of the same template, an array is always returned, and so we need to ask for `te.templates['Infobox cheese'][0]` to get the actual `Template`. To get the parameters:\n\n.. code-block:: python\n\n >>> te.templates['Infobox cheese'][0].parameters\n \n\nLet's say we want to change the value of the `protein` parameter from 10 to 7. We then use\nthe `wikitext()` method to return our new wikitext:\n\n.. code-block:: python\n\n >>> te.templates['Infobox cheese'][0].parameters['protein'] = 7\n >>> print te.wikitext()\n {{Infobox cheese\n | name = Mozzarella\n | protein = 10\n }}\n Mozzarella is a cheese\u2026{{tr}}\n\nNotice that formatting is preserved. We could now go and add a new parameter like so:\n\n.. code-block:: python\n\n >>> te.templates['Infobox cheese'][0].parameters['fat'] = 25\n >>> print te.wikitext()\n {{Infobox cheese\n | name = Mozzarella\n | protein = 7\n | fat = 25\n }}\n Mozzarella is a cheese\u2026{{tr}}\n\n\nUsage with mwclient to edit pages on Wikipedia\n----------------------------------------------\n\nUpdating a page on Wikipedia using `mwclient `_\n\n.. code-block:: python\n\n from mwclient import Site\n from mwtemplates import TemplateEditor\n\n site = Site('en.wikipedia.org')\n site.login('USERNAME', 'PASSWORD')\n page = site.pages['SOME_PAGE']\n te = TemplateEditor(page.text())\n if 'SOME_TEMPLATE' in page.templates:\n tpl = te.templates['SOME_TEMPLATE'][0]\n tpl.parameters['test'] = 'Hello'\n page.save(te.wikitext(), summary='...')\n\nRemoving a template argument:\n\n.. code-block:: python\n\n from mwtemplates import TemplateEditor\n te = TemplateEditor(u\"Hello {{mytpl | a=2 | b=3 | c=4 }} world\")\n te.templates['mytpl'].parameters.remove('b')\n\nRemoving the first instance of a template:\n\n.. code-block:: python\n\n from mwtemplates import TemplateEditor\n te = TemplateEditor(u\"Hello {{mytpl}} world {{mytpl}}\")\n te.templates['mytpl'][0].remove()\n\n\nContributing\n------------\n\nPull requests are very welcome. Please run tests before submitting:\n\n.. code-block:: console\n\n $ python setup.py test", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/danmichaelo/mwtemplates", "keywords": "mediawiki wikipedia", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "mwtemplates", "package_url": "https://pypi.org/project/mwtemplates/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/mwtemplates/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/danmichaelo/mwtemplates" }, "release_url": "https://pypi.org/project/mwtemplates/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "MediaWiki template parser and editor", "version": "0.4.0" }, "last_serial": 2004613, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "521fc1e2de2c90b3eef63deac4abe480", "sha256": "b6142d30fed1dd6e01583ffb24c93275e22a85937089e1147eafe4e870a21b4c" }, "downloads": -1, "filename": "mwtemplates-0.1.tar.gz", "has_sig": false, "md5_digest": "521fc1e2de2c90b3eef63deac4abe480", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14236, "upload_time": "2013-05-13T19:48:55", "url": "https://files.pythonhosted.org/packages/37/89/1c6d1f85914bc8d815d102569820793fe33b25df02aef94f83afa88622d0/mwtemplates-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "473bd6320a104d8250865641c4bded34", "sha256": "358771321ff897134862f1960c242bfac5d150310942462f0841aae22dd125ec" }, "downloads": -1, "filename": "mwtemplates-0.2.tar.gz", "has_sig": false, "md5_digest": "473bd6320a104d8250865641c4bded34", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14489, "upload_time": "2013-09-01T13:33:00", "url": "https://files.pythonhosted.org/packages/78/de/2a507d1b613fb4fbe536236647a3117bae55c61d8a0c3f7bdbf30f49e252/mwtemplates-0.2.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "22b69b6ffdf9bf48b1b7bedb9b2488fb", "sha256": "7adf9d7ae426961b9f6cd831f2d9d0e4b356bd17aa84381b6b698c75412d8e17" }, "downloads": -1, "filename": "mwtemplates-0.3.0.tar.gz", "has_sig": false, "md5_digest": "22b69b6ffdf9bf48b1b7bedb9b2488fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10885, "upload_time": "2014-08-02T12:49:54", "url": "https://files.pythonhosted.org/packages/41/b0/64708e4fe4bb1d7821a97cbd80245d1604db9ec1d71e3eecd98c55807041/mwtemplates-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "83c658d21cf4130f0f2de704ec67b788", "sha256": "d769a96d81c2e0cfe880020513abc227d770cfb341d8ff20f1520c0f95cad5da" }, "downloads": -1, "filename": "mwtemplates-0.3.1.tar.gz", "has_sig": false, "md5_digest": "83c658d21cf4130f0f2de704ec67b788", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10961, "upload_time": "2014-10-25T16:59:44", "url": "https://files.pythonhosted.org/packages/d5/37/5f0a78274316bebdebedd9efd190197270fb2f27033003f62fb297270e62/mwtemplates-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "e1e41bade4732fb5022feb3d05e22174", "sha256": "f483caf5d95d9dfe5eb1da48dc0d3c9beec551308674329ea60bda8858413b98" }, "downloads": -1, "filename": "mwtemplates-0.3.2.tar.gz", "has_sig": false, "md5_digest": "e1e41bade4732fb5022feb3d05e22174", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10987, "upload_time": "2014-10-25T17:12:01", "url": "https://files.pythonhosted.org/packages/ee/7d/faa12ec725f84908311004c1acce090413e8ebea71e77590070cb86f0a51/mwtemplates-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "8e8b147eebd779aedbf7631d6943fb18", "sha256": "a680d85ad4e6454af8588b033086cafd9c8397421a3a3342f76de23a137686a3" }, "downloads": -1, "filename": "mwtemplates-0.3.3.tar.gz", "has_sig": false, "md5_digest": "8e8b147eebd779aedbf7631d6943fb18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11778, "upload_time": "2014-11-22T22:04:17", "url": "https://files.pythonhosted.org/packages/c0/50/99ba4e0005c0f496b04120b55268b77ec32bea4e1348b1893829eb34919c/mwtemplates-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "041341197f02c68613c2bad9a33291d2", "sha256": "0a38079f1ab9fb78b00a653ee41a6fe7ae2de4cced6bc0e14f6810810141e71f" }, "downloads": -1, "filename": "mwtemplates-0.3.4.tar.gz", "has_sig": false, "md5_digest": "041341197f02c68613c2bad9a33291d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11975, "upload_time": "2015-12-22T01:01:09", "url": "https://files.pythonhosted.org/packages/45/ec/82ba0652bc2d99a38da4496aec0d74977c467525e0c4945d2755c2532f25/mwtemplates-0.3.4.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "6ad21d1045fb3fecb2e456422b910e6f", "sha256": "a265958c469d33d7609f91a263b321dee8afac89ba57d918b03ee59eba2a8a28" }, "downloads": -1, "filename": "mwtemplates-0.4.0.tar.gz", "has_sig": false, "md5_digest": "6ad21d1045fb3fecb2e456422b910e6f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12201, "upload_time": "2016-03-13T17:53:18", "url": "https://files.pythonhosted.org/packages/df/24/0fb60d8b32695def78bcd27adf749c178638a42dc3de4ea859a4b15290f2/mwtemplates-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6ad21d1045fb3fecb2e456422b910e6f", "sha256": "a265958c469d33d7609f91a263b321dee8afac89ba57d918b03ee59eba2a8a28" }, "downloads": -1, "filename": "mwtemplates-0.4.0.tar.gz", "has_sig": false, "md5_digest": "6ad21d1045fb3fecb2e456422b910e6f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12201, "upload_time": "2016-03-13T17:53:18", "url": "https://files.pythonhosted.org/packages/df/24/0fb60d8b32695def78bcd27adf749c178638a42dc3de4ea859a4b15290f2/mwtemplates-0.4.0.tar.gz" } ] }