Manual:Pywikibot/Recipes

On this page you will find short snippets of code showing the framework usage by the various bots.

Get language links for all pages
Iterate through wiki pages (possibly with additional filters), and for each page get all listed languagelinks.


 * API

query&generator=allpages&gapfrom=T&prop=langlinks
 * API langlinks limits could make result incomplete for any page without any notification, making batch processing much more difficult - client needs to do more querycontinue calls to know there are no more langlinks for the specific page.


 * Pywikipediabot

Get language links for a set of pages
For a user-supplied list of titles, resolve redirects and get their language links.


 * API

query&prop=langlinks&titles=T|TT&redirects


 * Pywikipediabot

Get non-resolved links and categories for a set of redirected pages
For each page in a set, if redirect, resolve to the redirect target, and get all links and all categories listed. Only link's namespace+title is needed.


 * API

|categories&titles=Archiver|Abstract%20(law)&pllimit=300&redirects query&prop=links|categories&titles=Archiver|Abstract%20(law)&pllimit=300&redirects


 * Pywikipediabot

Page generator -> get links and categories
From all pages in a wiki (possibly filtered), get all links and all categories listed. Only link's namespace+title is needed. Result pages (not links) might need to be edited.


 * API

|categories query&generator=allpages&gapfrom=T&prop=links|categories


 * Pywikipediabot

Modify a page
Given a page title, get the page content (if redirect, get the target), change and save it.


 * API

query&titles=Think&redirects&prop=revisions&rvprop=content [http://en.wikipedia.org/w/api.php?action=edit&summary=...&text=...&token=... edit&summary=...&text=...&token=...]


 * Pywikipediabot