jenkins-bot submitted this change.

View Change

Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
[doc] Provide a script example with the package instead of the content list

Change-Id: Ia903bc7c56674392c220601e544eca4438bfe96b
---
M README.rst
1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index cefa791..d23d3eb 100644
--- a/README.rst
+++ b/README.rst
@@ -101,11 +101,51 @@
item = pywikibot.ItemPage(repo, 'Q91') # a repository item
data = item.get() # get all item data from repository for this item

+Script example
+--------------
+
+Pywikibot provides bot classes to develop your own script easily:
+
+::
+
+ import pywikibot
+ from pywikibot import pagegenerators
+ from pywikibot.bot import ExistingPageBot
+
+ class MyBot(ExistingPageBot):
+
+ update_options = {
+ 'text': 'This is a test text',
+ 'summary: 'Bot: a bot test edit with Pywikbot.'
+ }
+
+ def treat_page(self):
+ """Load the given page, do some changes, and save it."""
+ text = self.current_page.text
+ text += '\n' + self.opt.text
+ self.put_current(text, summary=self.opt.summary)
+
+ def main():
+ """Parse command line arguments and invoke bot."""
+ options = {}
+ gen_factory = pagegenerators.GeneratorFactory()
+ # Option parsing
+ local_args = pywikibot.handle_args(args) # global options
+ local_args = gen_factory.handle_args(local_args) # generators options
+ for arg in local_args:
+ opt, sep, value = arg.partition(':')
+ if opt in ('-summary', '-text'):
+ options[opt[1:]] = value
+ MyBot(generator=gen_factory.getCombinedGenerator(), **options).run()
+
+ if __name == '__main__':
+ main()
+
+
-------------------------------------------------------------------------------------------

For more documentation on Pywikibot see our `docs <https://doc.wikimedia.org/pywikibot/>`_.

-.. include:: pywikibot/DIRECTORIES.rst

Required external programs
---------------------------

To view, visit change 699734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia903bc7c56674392c220601e544eca4438bfe96b
Gerrit-Change-Number: 699734
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged