jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/703030 )
Change subject: [doc] Start with a recipes page
......................................................................
[doc] Start with a recipes page
Change-Id: Ic31e45ffb20df94bb412f09cb11ba3695fa8deef
---
M docs/index.rst
A docs/recipes.rst
2 files changed, 25 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/index.rst b/docs/index.rst
index a428078..7bc1f1b 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -57,6 +57,7 @@
installation
library_usage
+ recipes
getting_help
api_ref/index
diff --git a/docs/recipes.rst b/docs/recipes.rst
new file mode 100644
index 0000000..2ee6ce9
--- /dev/null
+++ b/docs/recipes.rst
@@ -0,0 +1,24 @@
+Recipes
+=======
+
+Page content
+------------
+
+**How to modify a page**
+ >>> page = pywikibot.Page(pywikibot.Site(), 'Sample page')
+ >>> new_content = page.text.replace('this', 'that')
+ >>> page.put(new_content, summary='Bot: Test edit')
+
+ See :doc:`library_usage` for more advanced samples.
+
+**How to get links from summary section of page**
+ >>> import pywikibot
+ >>> from pwikibot import textlib
+ >>> site = pywikibot.Site('wikipedia:en') # create a Site object
+ >>> page = pywikibot.Page(site, 'Deep learning') # create a Page
object
+ >>> sect = textlib.extract_sections(page.text, site) # divide content into
sections
+ >>> links = sorted(link.group('title') for link in
pywikibot.link_regex.finditer(sect.head))
+ >>> pages = [pywikibot.Page(site, title) for title in links]
+
+ ``links`` is a list containing all link titles in alphabethical order.
+ ``pages`` is a sorted list containing all ``Page`` objects
\ No newline at end of file
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/703030
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic31e45ffb20df94bb412f09cb11ba3695fa8deef
Gerrit-Change-Number: 703030
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged