Jump to content

Vadovas:Pywikibot/pagegenerators.py

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/pagegenerators.py and the translation is 39% complete.
Outdated translations are marked like this.

pagegenerators.py is a Pywikibot script used to generate list of pages for other scripts.

Šis modulis siūlo įvairius puslapių generatorius. Puslapių generatorius yra objektas, kurį galima iteruoti (žr. https://www.python.org/dev/peps/pep-0255/) ir kuris duoda puslapių objektus, kuriems gali būti naudojami skriptai.

Komandinės eilutės panaudojimas

The pagegenerators.py may not be executed directly. Instead, the script listpages.py can be used.

Pavyzdys:

$ python pwb.py listpages -search:'foobar'

This will return, in standard output, a list of all pages containing "foobar", as returned by MediaWiki's search engine.

See listpages.py for more details.

Calls from another script

Kategorijų skaitytuvas:

from pywikibot import pagegenerators

site = pywikibot.Site()
cat = pywikibot.Category(site, 'Category name')
pages = cat.articles()
for page in pagegenerators.PreloadingGenerator(pages, 100):
    # some treatment of generated pages

Subkategorijų tyrinėtojas:

gen = pagegenerators.CategorizedPageGenerator(cat, recurse=True)

MySQL užklausos:

gen = pagegenerators.MySQLPageGenerator(query)

Unikodo rekomendacija

The following code returns KeyError: 'query' because of the special character:

gen = pagegenerators.SearchPageGenerator('´', namespaces = [0])

If searching in user and mediawiki namespaces, it would look like

gen = pagegenerators.SearchPageGenerator('´', namespaces = [2, 8])

Consequently, an encoding conversion is needed:

gen = pagegenerators.SearchPageGenerator("´", namespaces = [0])

See also